Operator performance
Posted: Fri Jan 22, 2010 10:29 pm
I haven't had any luck searching for the answer and I'm too lazy to code up my own test (maybe I will if no one knows). It is probably language dependent....but is there any performance difference between the two following code samples:
To a human brain, less/greater than would seem to require an extra step compared to not equal. But when it comes to data in a computer it seems like you would have to compare every bit in until one didn't match in both scenarios. My guess is that not equal is still faster because you can immediately calculate half of all possible comparisons based on the first bit alone.
Code: Select all
uint length = someArray.length - 1;
uint n = 0;
while (n != length) {n++;}
Code: Select all
uint length = someArray.length;
uint n = 0;
while (n < length) {n++;}