You're right. I never use gettimeofday, and mistakenly assumed it returned millseconds not microseconds.

Now, beside being wrong, you are also inconsistent. In your first point, you accuse me of not dividing by the number of iterations, as if the value wouldn't be a number of sub-second units. Then in your second point you do think it's a number of sub-second units. You can't have it both ways.

I misunderstood your arcane way of doing floating point math and thought you were dividing by the (wrong) number of iterations. I misundertsood your code, for which I apologise, but there is no inconsistancy. Good enough reason to use a module rather than hand code the math.

I also noted "Without having analysed it too closely, you appear to have a precedence problem in your delta calculations.".

That said, even if we return to using your arcane floating point math and bizarre failure to break down the results on a per iteration basis, the results of your benchmark method, modified by the removal of your $a fopar, still shows that & 1 is consistantly faster than % 2.

#! perl -slw use strict; use Time::HiRes 'gettimeofday'; our $ITERS ||= 10_000_000; my $counter1 = 0; my $counter2 = 0; my( $s1, $m1 ) = gettimeofday; for (1 .. $ITERS) { ++$counter1 & 1 and 1 } my( $s2, $m2 ) = gettimeofday; for (1 .. $ITERS) { ++$counter2 % 2 and 1 } my( $s3, $m3 ) = gettimeofday; my $d1 = $s2 - $s1 + ($m2 - $m1) / 1_000_000; my $d2 = $s3 - $s2 + ($m3 - $m2) / 1_000_000; printf "And: %.9f Mod: %.9f\n", $d1, $d2; __END__ c:\test>junk2 -ITERS=1e6 And: 0.258308000 Mod: 0.304192000 c:\test>junk2 -ITERS=1e6 And: 0.258755000 Mod: 0.272495000 c:\test>junk2 -ITERS=1e6 And: 0.259628000 Mod: 0.302872000 c:\test>junk2 -ITERS=10e6 And: 2.656250000 Mod: 2.828125000 c:\test>junk2 -ITERS=10e6 And: 2.671875000 Mod: 2.859375000 c:\test>junk2 -ITERS=10e6 And: 2.671875000 Mod: 2.859375000 c:\test>junk2 -ITERS=100e6 And: 26.187500000 Mod: 28.375000000 c:\test>junk2 -ITERS=100e6 And: 26.265625000 Mod: 28.328125000

And the more iterations you run (therebye reducing the obscuring affects of the invariant parts of the code under test), the more consistant it becomes.

Just as was shown by both my Benchmark method and lidden's external timer method.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^5: &1 is no faster than %2 when checking for oddness. (Careful what you benchmark) by BrowserUk
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.