diff options
author | David Mitchell <davem@iabyn.com> | 2015-11-26 13:51:29 +0000 |
---|---|---|
committer | David Mitchell <davem@iabyn.com> | 2015-11-26 16:04:54 +0000 |
commit | babeed279c5f867ce4148669b3bf8f30e8254a9f (patch) | |
tree | ecd2545cea9eec0d314503c5e48db671a23e5451 /lib | |
parent | c0236afee0c5845d3823612c5cd34eccc4d29321 (diff) | |
download | perl-babeed279c5f867ce4148669b3bf8f30e8254a9f.tar.gz |
Benchmark: move elapsed time calc into method
A couple of places do basically the same set of summing various times()
fields within a Benchmark object, so make it into a private method.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Benchmark.pm | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/lib/Benchmark.pm b/lib/Benchmark.pm index b301678808..1d272a7d33 100644 --- a/lib/Benchmark.pm +++ b/lib/Benchmark.pm @@ -482,7 +482,7 @@ our(@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $VERSION); clearcache clearallcache disablecache enablecache); %EXPORT_TAGS=( all => [ @EXPORT, @EXPORT_OK ] ) ; -$VERSION = 1.20; +$VERSION = 1.21; # --- ':hireswallclock' special handling @@ -585,6 +585,17 @@ sub cpu_a { my($r,$pu,$ps,$cu,$cs) = @{$_[0]}; $pu+$ps+$cu+$cs ; } sub real { my($r,$pu,$ps,$cu,$cs) = @{$_[0]}; $r ; } sub iters { $_[0]->[5] ; } +# return the sum of various times: which ones depending on $style + +sub elapsed { + my ($self, $style) = @_; + $style = "" unless defined $style; + + return $self->cpu_c if $style eq 'nop'; + return $self->cpu_p if $style eq 'noc'; + return $self->cpu_a; +} + $_Usage{timediff} = <<'USAGE'; usage: $result_diff = timediff($result1, $result2); @@ -647,11 +658,7 @@ 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'; - my $elapsed = do { - if ($style eq 'nop') {$cu+$cs} - elsif ($style eq 'noc') {$pu+$ps} - else {$cu+$cs+$pu+$ps} - }; + my $elapsed = $tr->elapsed($style); $s .= sprintf(" @ %$f/s (n=$n)",$n/($elapsed)) if $n && $elapsed; $s; } @@ -973,13 +980,11 @@ sub cmpthese{ my @vals = map{ [ $_, @{$results->{$_}} ] } keys %$results; for (@vals) { + # recreate the pre-flattened Benchmark object + my $tmp_bm = bless [ @{$_}[1..$#$_] ]; + my $elapsed = $tmp_bm->elapsed($style); # The epsilon fudge here is to prevent div by 0. Since clock # resolutions are much larger, it's below the noise floor. - my $elapsed = do { - if ($style eq 'nop') {$_->[4]+$_->[5]} - elsif ($style eq 'noc') {$_->[2]+$_->[3]} - else {$_->[2]+$_->[3]+$_->[4]+$_->[5]} - }; my $rate = $_->[6]/(($elapsed)+0.000000000000001); $_->[7] = $rate; } |