INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

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:

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

It depends on whether the implementation of SIGN has jumps in it. On some machine architectures, it is a built in instruction so there won't be any jumps. If SIGN has jumps, you're just trading one set of jumps for another.

RE: Efficiency of if-construct

The way I see it, the second loop structure would be much faster...first of all, I thought IF evaluations were pretty fast; second, the second loop does not have multiplications or summations, it is just a straight out assignment.

RE: Efficiency of if-construct

(OP)
I have checked both versions on a quadcore i7 both under Windows 8.1 and Ubuntu 14.04 LTS, compiled with Absoft 14.0. For a problem consuming ~10 minutes of CPU time, the difference between both versions was less than a few seconds. So i will stay with the IF blocks with their superior readability.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close