Could you please create a bug report using perlbug and mail it in? I've reported this myself in the past, and it would be nice to have third party confirmation on it. We need to know your perl version and os and the test snippet you posted. For instance I'm on Win32, and if you aren't it would mean that the problem has wider impact than currently beleived.

Just for information's sake I believe the problem is due to Benchmark trying to remove the timing for the "empty" loop from the results. Elsewhere in this thread you said something like "I dont need something to run two loops and subtract the times for me", but thats not what Benchmark does. It also times an empty loop. It them subtracts the empty loop time from the originals before doing the compare, the idea being to eliminate the overhead of the loop and timing process itself.

Where this goes is wrong is when the amount of time it takes to benchmark your code is withing the granularity of the timing routines (or the underlying numerical properties of the representation of the time). At that point you end up with the one-tick/two-tick problem (a call starts and ends within the same timestamp effectively having 0 time, or a call starts an ends in adjacent timestamps and thus has a non-zero time, even tho both take the same time to complete. (Nyquist comes to mind)).

When the thing being benchmarked take a few times longer than the empty loop the difference averages out and results are pretty accurate, for timing fast things, IMO its pretty useless. What would be cool is if Benchmark detected the underlying loop was too fast that it disabled the empty loop subtraction. (Actually I wouldnt care if the empty loop was never removed, as I see it as a "fair penalty" on both.)

So with your benchmark what is happening is you are timing two empty loops, subtracting one from the other and then seeing the consequence of noise in the calculation. Which as I've explained can easily result in negative times. When combined with negative times it cause Benchmark to go into a degenerate loop, each time increasing the number of iterations it should use to get an good timing, in some cases this can result in an overflow of the for (0..x) {}. (I've seen this in make test left overnight.)

---
$world=~s/war/peace/g


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