diff options
author | David Mitchell <davem@iabyn.com> | 2015-11-26 15:41:01 +0000 |
---|---|---|
committer | David Mitchell <davem@iabyn.com> | 2015-11-26 16:04:54 +0000 |
commit | 8dddc15610773a292e6fe8f989e51dd8c27ac1de (patch) | |
tree | 48d2f92ed26a38e3b2d0c18da3d28f60a9805aeb /lib/Benchmark.t | |
parent | babeed279c5f867ce4148669b3bf8f30e8254a9f (diff) | |
download | perl-8dddc15610773a292e6fe8f989e51dd8c27ac1de.tar.gz |
Benchmark.t/.pm: deal with short times
The number of iterations to do on various tests was set at 3 or 10
in the first incarnation of the test file 13 years ago, and hasn't
changed since. In the meantime, CPUs have gotten faster. So bump the
iteration count to 100. This makes no appreciable difference to total wall
time for the test file on my newish x86_64 platform, but will hopefully
make tests less likely to be running within the noise of a single 100Hz
clock tick.
In particular, the NetBSD smokes were quite frequently failing tests 127
and 128, due to the CPU taken to do an empty loop being greater than that
for a full loop, thus leading to negative apparent execution time. This
was likely to be due to the first taking "1" clock tick and the second
taking "0" ticks. Although this is less likely to happen now that the
iterations has been increased, this commit also adds a check to
Benchmark.pm for a negative apparent execution time, and if detected,
prints a "too few iterations" warning and resets it to zero.
Diffstat (limited to 'lib/Benchmark.t')
-rw-r--r-- | lib/Benchmark.t | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/Benchmark.t b/lib/Benchmark.t index 680e50d574..080641d7f9 100644 --- a/lib/Benchmark.t +++ b/lib/Benchmark.t @@ -144,7 +144,7 @@ is ($auto, $default, 'timestr ($diff, "auto") matches timestr ($diff)'); my $out = tie *OUT, 'TieOut'; -my $iterations = 3; +my $iterations = 100; $foo = 0; select(OUT); @@ -447,7 +447,7 @@ sub check_graph { { $foo = $bar = 0; select(OUT); - my $chart = cmpthese( 10, $code_to_test, 'nop' ) ; + my $chart = cmpthese($iterations, $code_to_test, 'nop' ) ; select(STDOUT); ok ($foo > 0, "Foo code was run"); ok ($bar > 0, "Bar code was run"); @@ -455,7 +455,7 @@ sub check_graph { $got = $out->read(); # Remove any warnings about having too few iterations. $got =~ s/\(warning:[^\)]+\)//gs; - like ($got, qr/timing 10 iterations of\s+Bar\W+Foo\W*?\.\.\./s, + like ($got, qr/timing $iterations iterations of\s+Bar\W+Foo\W*?\.\.\./s, 'check title'); # Remove the title $got =~ s/.*\.\.\.//s; @@ -467,7 +467,7 @@ sub check_graph { { $foo = $bar = 0; select(OUT); - my $chart = cmpthese( 10, $code_to_test, 'none' ) ; + my $chart = cmpthese($iterations, $code_to_test, 'none' ) ; select(STDOUT); ok ($foo > 0, "Foo code was run"); ok ($bar > 0, "Bar code was run"); @@ -484,10 +484,13 @@ sub check_graph { check_graph (@$chart); } +# this is a repeat of the above test, but with the timing and charting +# steps split. + { $foo = $bar = 0; select(OUT); - my $res = timethese( 10, $code_to_test, 'none' ) ; + my $res = timethese($iterations, $code_to_test, 'none' ) ; my $chart = cmpthese($res, 'none' ) ; select(STDOUT); ok ($foo > 0, "Foo code was run"); |