C# evaluate for a value greater than 0 given 3 variables -



C# evaluate for a value greater than 0 given 3 variables -

is more efficient use: if ( a+b+c > 0) or if ( a>0 || b>0|| c>0) or there improve way either of these?

these 2 expressions not equivalent: first look false a=1, b=0, c=-1, while sec true.

the first look require 2 additions, comparing zero, , branch, while sec look require 3 comparisons 0 , 3 branches, because || operator short-circuiting. in end, difference going undetectably small.

the case when sec look win when a, b , c represent expensive computations:

if (expensivecomputationa() > 0 || expensivecomputationb() > 0 || expensivecomputationc() > 0) { ... }

since computation above stop after first success, resultant code faster result of short-circuiting expensive branches.

c#

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -