Journal Jarlsberg's Journal: A note on modulus
Using bitwise operators are faster than modulus operators, right? Apparently this is not the case with PHP.
At Magicode.org, I've taken a hard look at whether using a ternary operator is faster than using modulus. I entered into this thinking the answer was obvious, the bitwise operator would win, hands down. Turns out, it ain't so.
Running several loops in varying steps, the most intensive being a consecutive loop from 0 to 1000000 (million) showed that $i%2 was significantly faster than $i&1==0, being about 9% faster in most tests. The results and the script used to verify the results are available at magicode.org.
So, there you go folks, modulus wins.
A note on modulus More Login
A note on modulus
Slashdot Top Deals