## Efficiency of if-construct

## Efficiency of if-construct

(OP)

I was wondering, which of the following code snippets would usually perform faster.

First avoiding IF statements within the loop, at the cost of a few additional arithmetic operations:

Second using IF blocks:

Of course i could just try out on one machine at least, but nevertheless any comments on this would be appreciated.

First avoiding IF statements within the loop, at the cost of a few additional arithmetic operations:

#### CODE

DO k = 2,n-2 DO i = 2,l-2 vvb = sign(0.5,v(i,2,k)) zwil1(i,1,k) = (0.5+vvb)*eps(i,1,k) - (vvb-0.5)*zwil1(i,2,k) END DO END DO

Second using IF blocks:

#### CODE

DO k = 2,n-2 DO i = 2,l-2 IF (v(i,2,k) .LT. 0.0) THEN zwil1(i,1,k) = zwil1(i,2,k) ELSE zwil1(i,1,k) = eps(i,1,k) END IF END DO END DO

Of course i could just try out on one machine at least, but nevertheless any comments on this would be appreciated.

## RE: Efficiency of if-construct

## RE: Efficiency of if-construct

## RE: Efficiency of if-construct