Sure. As you can see, it's not the lexically first test that gets the biased. It's the first iteration of that test. Which explains why the bias is more pronounced the less runs you do.

By running all the tests once and discarding the results, you even up the playing field and the seconds cmpthese shows a much better distribution.

You should also consider shutting down as much else that is running on your box for the duration of the tests. For example, if my dial connection times out during a test, a high priority thread runs for the duration of the reconnect. That can completely skew the results.

Even using the mouse to pop up the task manager will have some effect. But if this is enough to obscure the gains you have made, it probably means that they are so small as to be subject to random variation anyway.

#! perl -slw use strict; use Benchmark qw[ cmpthese ]; our $ITERS ||= 5; our $REPS ||= 10000; sub test { my @strings = map{ ' ' x 1000 } 1 .. $REPS; } my %tests = ( Atest => \&test, Btest => \&test, Ctest => \&test, Dtest + => \&test, ); ## Ignore the results produced by this run cmpthese( 1, \%tests); ## These should show more even distribution. cmpthese( $ITERS, \%tests); P:\test>373536-2 -ITERS=10 Rate Dtest Btest Ctest Atest Dtest 4.27/s -- -0% -7% -67% Btest 4.27/s 0% -- -7% -67% Ctest 4.59/s 7% 7% -- -64% Atest 12.8/s 200% 200% 179% -- Rate Ctest Dtest Atest Btest Ctest 4.10/s -- -1% -1% -1% Dtest 4.13/s 1% -- -0% -0% Atest 4.13/s 1% 0% -- -0% Btest 4.13/s 1% 0% 0% --

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon

In reply to Re^5: Benchmark.pm: Does subroutine testing order bias results? by BrowserUk
in thread Benchmark.pm: Does subroutine testing order bias results? by jkeenan1

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.