From: Gurusamy Sarathy Date: Fri, 15 Oct 1999 01:34:09 +0000 (+0000) Subject: Benchmark notes (from Barrie Slaymaker ) X-Git-Tag: accepted/trunk/20130322.191538~35965 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=54e82ce5cfd72fcdc60806373e0c4d6890b68a3c;p=platform%2Fupstream%2Fperl.git Benchmark notes (from Barrie Slaymaker ) p4raw-id: //depot/perl@4384 --- diff --git a/lib/Benchmark.pm b/lib/Benchmark.pm index 9196673..83331aa 100644 --- a/lib/Benchmark.pm +++ b/lib/Benchmark.pm @@ -269,6 +269,35 @@ calls like these: Caching is off by default, as it can (usually slightly) decrease accuracy and does not usually noticably affect runtimes. +=head1 EXAMPLES + +For example, + + use Benchmark;$x=3;cmpthese(-5,{a=>sub{$x*$x},b=>sub{$x**2}}) + +outputs something like this: + + Benchmark: running a, b, each for at least 5 CPU seconds... + a: 10 wallclock secs ( 5.14 usr + 0.13 sys = 5.27 CPU) @ 3835055.60/s (n=20210743) + b: 5 wallclock secs ( 5.41 usr + 0.00 sys = 5.41 CPU) @ 1574944.92/s (n=8520452) + Rate b a + b 1574945/s -- -59% + a 3835056/s 144% -- + +while + + use Benchmark; + $x=3; + $r=timethese(-5,{a=>sub{$x*$x},b=>sub{$x**2}},'none'); + cmpthese($r); + +outputs something like this: + + Rate b a + b 1559428/s -- -62% + a 4152037/s 166% -- + + =head1 INHERITANCE Benchmark inherits from no other class, except of course diff --git a/pod/perldelta.pod b/pod/perldelta.pod index b4d4d21..3ff77cc 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -1035,25 +1035,43 @@ The Dumpvalue module provides screen dumps of Perl data. =item Benchmark +Overall, Benchmark results exhibit lower average error and better timing +accuracy. + You can now run tests for I seconds instead of guessing the right number of tests to run: e.g. timethese(-5, ...) will run each code for at least 5 CPU seconds. Zero as the "number of repetitions" means "for at least 3 CPU seconds". The output format has also changed. For example: -use Benchmark;$x=3;timethese(-5,{a=>sub{$x*$x},b=>sub{$x**2}}) + use Benchmark;$x=3;timethese(-5,{a=>sub{$x*$x},b=>sub{$x**2}}) will now output something like this: -Benchmark: running a, b, each for at least 5 CPU seconds... - a: 5 wallclock secs ( 5.77 usr + 0.00 sys = 5.77 CPU) @ 200551.91/s (n=1156516) - b: 4 wallclock secs ( 5.00 usr + 0.02 sys = 5.02 CPU) @ 159605.18/s (n=800686) + Benchmark: running a, b, each for at least 5 CPU seconds... + a: 5 wallclock secs ( 5.77 usr + 0.00 sys = 5.77 CPU) @ 200551.91/s (n=1156516) + b: 4 wallclock secs ( 5.00 usr + 0.02 sys = 5.02 CPU) @ 159605.18/s (n=800686) New features: "each for at least N CPU seconds...", "wallclock secs", and the "@ operations/CPU second (n=operations)". -change#4265,4266,4292 -[TODO - Barrie Slaymaker ] +timethese() now returns a reference to a hash of Benchmark objects containing +the test results, keyed on the names of the tests. + +timethis() now returns the iterations field in the Benchmark result object +instead of 0. + +timethese(), timethis(), and the new cmpthese() (see below) can also take +a format specifier of 'none' to suppress output. + +A new function countit() is just like timeit() except that it takes a +TIME instead of a COUNT. + +A new function cmpthese() prints a chart comparing the results of each test +returned from a timethese() call. For each possible pair of tests, the +percentage speed difference (iters/sec or seconds/iter) is shown. + +For other details, see L. =item Devel::Peek