in reply to &1 is no faster than %2 when checking for oddness. Oh well.

You're getting old. A trick like this made a huge difference in the time where division was an expensive operation. But since the FPU coprocessors became common, about 10 years ago, division is, in practice, as fast as any other operation. So it will no longer make much of a difference. Definitely not as much as it did 10 years ago.

Furthermore, you're testing this in Perl, not in C or in assembler. Perl has such a huge overhead that even if bare division took twice as long as bitwise and, by the time you get to the level of interpreted Perl, you lost most of your advantage.

  • Comment on Re: &1 is no faster than %2 when checking for oddness. Oh well.

Replies are listed 'Best First'.
Re^2: &1 is no faster than %2 when checking for oddness. Oh well.
by diotalevi (Canon) on Nov 17, 2006 at 20:47 UTC

    ysth told me that IlyaZ once wrote a paper where he finds that all of these minor perlops are equal in overhead.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊