Your benchmark still has a flaw; it's using the same variable to increment. So one case is incrementing from 0, the other from where the first one left off. It may not make a difference, but how can you be sure.

Of course, the biggest flaw is the use the Benchmark module itself. How can use trust a module that sometimes reports negative times?

#!/usr/bin/perl use strict; use warnings; use Time::HiRes 'gettimeofday'; my $ITERATIONS = 10_000_000; my $counter1 = 0; my $counter2 = 0; my ($s1, $m1) = gettimeofday; for (1 .. $ITERATIONS) {$a = ++$counter1 & 1} my ($s2, $m2) = gettimeofday; for (1 .. $ITERATIONS) {$a = ++$counter2 % 2} my ($s3, $m3) = gettimeofday; my $d1 = $s2 - $s1 + ($m2 - $m1) / 1_000_000; my $d2 = $s3 - $s2 + ($m3 - $m2) / 1_000_000; printf "And: %.6f Mod: %.6f\n", $d1, $d2; __END__ And: 2.954181 Mod: 3.093696 And: 3.320696 Mod: 3.321606 And: 3.096083 Mod: 3.218991 And: 2.977993 Mod: 3.113543 And: 2.954634 Mod: 3.100933 And: 2.836724 Mod: 3.168724 And: 2.880770 Mod: 3.472917 And: 3.117684 Mod: 3.552177 And: 3.668317 Mod: 3.616199 And: 3.126708 Mod: 3.126385

In reply to Re^2: &1 is no faster than %2 when checking for oddness. (Careful what you benchmark) by Anonymous Monk
in thread &1 is no faster than %2 when checking for oddness. Oh well. by diotalevi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.