Bencher/Formatter/RoundNumbers.pm

filter: Statementstmt 50.0% 26 / 52 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 77.7% 7 / 9 Podpod 0.0% 0 / 1 totaltotal 34.3% 33 / 96 CC 15 SCAR 46.5
CC
15
Cov
33%
munge_result
182.0
__ANON__
12.0
BEGIN
1.0
CRAP 104.7
« Bencher/Formatter/ScaleSize.pm ↑ Summary Bencher/Formatter/ScaleTime.pm »
1 package Bencher::Formatter::RoundNumbers;
2  
3 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 #use Log::Any::IfLOG '$log';
7  
8 1 ▶use parent qw(Bencher::Formatter);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Math::ScientificNotation::Util qw(sci2dec);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use Role::Tiny::With;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 with 'Bencher::Role::ResultMunger';
15  
16 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
17 1 our $DATE = '2023-07-08'; # DATE
18 1 our $DIST = 'Bencher-Backend'; # DIST
19 1 our $VERSION = '1.063'; # VERSION
20  
21 0 ▶sub munge_result {
Subroutine munge_result: not called CC=13 SCAR=52.0
Pod undocumented
22 0 my ($self, $envres) = @_;
23  
24 0 my $ff = $envres->[3]{'table.fields'};
25  
26 0 ▶ my $code_fmt = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
27 0 my ($num_significant_digits, $num, $scientific_notation) = @_;
28 0 ▶ $scientific_notation //= $self->{scientific_notation};
Condition0%0/3
$scientific_notation //= $self->{"scientific_notation"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$scientific_notation //= $self->{"scientific_notation"}
$scientific_notation $self->{"scientific_notation"}
Truth table0%0/3
A //= B
A= $scientific_notationB= $self->{"scientific_notation"}
ABresult
1X1
011
000
29 0 $num = sprintf("%.${num_significant_digits}g", $num);
30 0 ▶ $num = sci2dec($num) unless $scientific_notation;
Branch: 1 branch
BranchTrueFalseTotal
unless $scientific_notation 0 0 0
31 0 $num;
32 0 };
33  
34 0 for my $rit (@{$envres->[2]}) {
35 0 my $num_significant_digits = do {
36 0 ▶ if (!defined($rit->{errors}) || $rit->{errors} == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $rit->{'errors'} or $rit->{'errors'} == 0) { } 0 0 0
elsif (exists $rit->{'time'}) { } 0 0 0
Condition0%0/3
not defined $rit->{"errors"} or $rit->{"errors"} == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $rit->{"errors"} or $rit->{"errors"} == 0
not defined $rit->{"errors"} $rit->{"errors"} == 0
Truth table0%0/3
not(A) or B
A= not defined $rit->{"errors"}B= $rit->{"errors"} == 0
ABresult
1X1
011
000
37 0 6;
38 } elsif (exists $rit->{time}) {
39 sprintf("%d", log( abs($rit->{time}) /
40 ($envres->[3]{'func.time_factor'} // 1) /
41 0 ▶ $rit->{errors} )/log(10));
Condition0%0/2
$envres->[3]{"func.time_factor"} // 1
l!l
00
MC/DC0%0/1
$envres->[3]{"func.time_factor"} // 1
$envres->[3]{"func.time_factor"}
Truth table0%0/2
A
A= $envres->[3]{"func.time_factor"}
Aresult
11
00
42 } else {
43 0 die "BUG: no 'time' defined?";
44 }
45 };
46 0 $rit->{time} = $code_fmt->($num_significant_digits, $rit->{time});
47 0 ▶ if (exists $rit->{rate}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rit->{"rate"}) 0 0 0
48 0 $rit->{rate} = $code_fmt->($num_significant_digits, $rit->{rate});
49 }
50 $rit->{errors} = $code_fmt->(2, $rit->{errors}, 1)
51 0 ▶ if defined $rit->{errors};
Branch: 1 branch
BranchTrueFalseTotal
if defined $rit->{"errors"} 0 0 0
52  
53 # XXX this formatter shouldn't be aware directly of mod_overhead_time
54 0 ▶ if (exists $rit->{mod_overhead_time}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rit->{"mod_overhead_time"}) 0 0 0
55 $rit->{mod_overhead_time} = $code_fmt->(
56 0 $num_significant_digits, $rit->{mod_overhead_time});
57 }
58 # XXX this formatter shouldn't be aware directly of vs_slowest
59 0 ▶ if (exists $rit->{vs_slowest}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rit->{"vs_slowest"}) 0 0 0
60 $rit->{vs_slowest} = $code_fmt->(
61 0 $num_significant_digits, $rit->{vs_slowest});
62 }
63  
64 # we don't need to round *_size fields to n significant digits because
65 # they are not time measurement, but we do want to round it when it has
66 # been divided when converting unit to kB, MB, etc.
67 0 for my $col (keys %$rit) {
68 0 ▶ if ($col =~ /^(result|proc_\w+|proc|arg_\w+)_size$/ && $rit->{$col} != int($rit->{$col})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($col =~ /^(result|proc_\w+|proc|arg_\w+)_size$/ and $rit->{$col} != int $rit->{$col}) 0 0 0
Condition0%0/3
$col =~ /^(result|proc_\w+|proc|arg_\w+)_size$/ and $rit->{$col} != int $rit->{$col}
!ll&&!rl&&r
000
MC/DC0%0/2
$col =~ /^(result|proc_\w+|proc|arg_\w+)_size$/ and $rit->{$col} != int $rit->{$col}
$col =~ /^(result|proc_\w+|proc|arg_\w+)_size$/ $rit->{$col} != int $rit->{$col}
Truth table0%0/3
A and B
A= $col =~ /^(result|proc_\w+|proc|arg_\w+)_size$/B= $rit->{$col} != int $rit->{$col}
ABresult
0X0
100
111
69 $rit->{$col} = $code_fmt->(
70 0 $num_significant_digits, $rit->{$col});
71 }
72 }
73 }
74 }
75  
76 1 1;
77 # ABSTRACT: Round numbers (rate, time) to certain significant digits according to errors
78  
79 __END__
« Bencher/Formatter/ScaleSize.pm ↑ Summary Bencher/Formatter/ScaleTime.pm »