Please create an account to participate in the Slashdot moderation system

 



Forgot your password?
typodupeerror
×
PHP

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.

This discussion has been archived. No new comments can be posted.

A note on modulus

Comments Filter:

This file will self-destruct in five minutes.

Working...