performance - C++ int comparison efficiency -


is there difference in performance of following code snippets? 1 performs best , why?

int = 1000000000;  while(i != 0) { i--; } 

or

int = 1000000000;  while(i) { i--; }  

or

int = 1000000000;  while(i > 0) { i--; } 

i see lot of people use first example , wonder why. easier read?

is there difference in performance of following code snippets?

no.

first 2 equivalent, , 3 can optimized same assembly.

i see lot of people use first example , wonder why. easier read?

it requires reader know fewer language rules second one. in particular, second program requires knowledge conditional expression converted bool, , conversion int has same result inequality zero.

note if i replaced floating point number, or if decrement modified have more complexity (for example: decrement 2), third option easiest prove correct. integers , single decrement, there no difference.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -