in reply to &1 is no faster than %2 when checking for oddness. Oh well.
no difference between the speed of ++$counter & 1 and ++$counter % 2. I thought there might be but I guess not
When you get down to the metal, an AND instruction probably executes in one clock cycle. A DIV/MOD instruction on a classic CISC architecture might take 40, then again, it might also take one clock cycle too. If the code is balanced on a razor's edge just so, your code that does the AND might just happen to consistently cause an L2 cache miss, and then your modulo will appear to be faster.
I would imagine that even if the machine instruction that performs a divide/modulo was two orders of magnitude slower, from the point of view of the perl interpreter there's so much else going on that the difference is going to be lost in the noise.
Which in fact, it turned out to be :)
• another intruder with the mooring in the heart of the Perl
|
|---|