X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FBenchmark.pm;h=ad04a754bbbab1b5dc8bebdc787e5b183db74eb9;hb=b1fbf5c3d1dc6dd7934002da04dede2ae2e3ef65;hp=3d154bc3214c7c47eee19808ec38d2d341bfeb9a;hpb=53aa2791f2814657eac3bbbec321e82f3209ae86;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/Benchmark.pm b/lib/Benchmark.pm index 3d154bc..ad04a75 100644 --- a/lib/Benchmark.pm +++ b/lib/Benchmark.pm @@ -412,6 +412,9 @@ All bugs found while writing a regression test. September, 2002; by Jarkko Hietaniemi: add ':hireswallclock' special tag. +February, 2004; by Chia-liang Kao: make cmpthese and timestr use time +statistics for children instead of parent when the style is 'nop'. + =cut # evaluate something in a clean lexical environment @@ -432,7 +435,7 @@ our(@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $VERSION); clearcache clearallcache disablecache enablecache); %EXPORT_TAGS=( all => [ @EXPORT, @EXPORT_OK ] ) ; -$VERSION = 1.051; +$VERSION = 1.07; # --- ':hireswallclock' special handling @@ -440,7 +443,7 @@ my $hirestime; sub mytime () { time } -&init; +init(); sub BEGIN { if (eval 'require Time::HiRes') { @@ -470,8 +473,8 @@ sub init { # The cache can cause a slight loss of sys time accuracy. If a # user does many tests (>10) with *very* large counts (>10000) # or works on a very slow machine the cache may be useful. - &disablecache; - &clearallcache; + disablecache(); + clearallcache(); } sub debug { $Debug = ($_[1] != 0); } @@ -482,9 +485,8 @@ sub usage { return $_Usage{$calling_sub} || ''; } - # The cache needs two branches: 's' for strings and 'c' for code. The -# emtpy loop is different in these two cases. +# empty loop is different in these two cases. $_Usage{clearcache} = <<'USAGE'; usage: clearcache($count); @@ -595,7 +597,8 @@ sub timestr { $r,$pu,$ps,$pt) if $style eq 'noc'; $s=sprintf("$w wallclock secs (%$f cusr + %$f csys = %$f CPU)", $r,$cu,$cs,$ct) if $style eq 'nop'; - $s .= sprintf(" @ %$f/s (n=$n)", $n / ( $pu + $ps )) if $n && $pu+$ps; + $s .= sprintf(" @ %$f/s (n=$n)", $n / ( $style eq 'nop' ? $cu + $cs : $pu + $ps )) + if $n && ($style eq 'nop' ? $cu+$cs : $pu+$ps); $s; } @@ -645,7 +648,7 @@ sub runloop { # &runloop a lot, and thus reduce additive errors. my $tbase = Benchmark->new(0)->[1]; while ( ( $t0 = Benchmark->new(0) )->[1] == $tbase ) {} ; - &$subref; + $subref->(); $t1 = Benchmark->new($n); $td = &timediff($t1, $t0); timedebug("runloop:",$td); @@ -883,7 +886,8 @@ sub cmpthese{ for (@vals) { # The epsilon fudge here is to prevent div by 0. Since clock # resolutions are much larger, it's below the noise floor. - my $rate = $_->[6] / ( $_->[2] + $_->[3] + 0.000000000000001 ); + my $rate = $_->[6] / (( $style eq 'nop' ? $_->[4] + $_->[5] + : $_->[2] + $_->[3]) + 0.000000000000001 ); $_->[7] = $rate; } @@ -891,7 +895,7 @@ sub cmpthese{ @vals = sort { $a->[7] <=> $b->[7] } @vals; # If more than half of the rates are greater than one... - my $display_as_rate = $vals[$#vals>>1]->[7] > 1; + my $display_as_rate = @vals ? ($vals[$#vals>>1]->[7] > 1) : 0; my @rows; my @col_widths;