Bencher/Formatter/ScaleTime.pm

filter: Statementstmt 45.6% 26 / 57 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 1 totaltotal 37.5% 33 / 88 CC 12 SCAR 45.9
CC
12
Cov
34%
munge_result
156.0
BEGIN
1.0
BEGIN
1.0
CRAP 98.9
« Bencher/Formatter/RoundNumbers.pm ↑ Summary Bencher/Formatter/RenderAsBenchmarkPm.pm »
1 package Bencher::Formatter::ScaleTime;
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 List::MoreUtils qw(minmax);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use POSIX ();
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=12 SCAR=50.5
Pod undocumented
22 0 my ($self, $envres) = @_;
23  
24 0 ▶ return unless @{$envres->[2]};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$envres->[2];} 0 0 0
25  
26 # pick an appropriate time unit & format the time
27 0 my ($min, $max) = minmax(map {$_->{time}} @{$envres->[2]});
28  
29 # workaround for bug RT#113117 (max sometimes undef)
30 0 ▶ $max //= $min;
Condition0%0/3
$max //= $min
l!l&&r!l&&!r
000
MC/DC0%0/2
$max //= $min
$max $min
Truth table0%0/3
A //= B
A= $maxB= $min
ABresult
1X1
011
000
31  
32 0 my $unit = "";
33 0 my $factor = 1;
34 0 ▶ if ($max <= 1.5e-6) {
Branch: 3 branches
BranchTrueFalseTotal
if ($max <= 1.5e-06) { } 0 0 0
elsif ($max <= 0.0015) { } 0 0 0
elsif ($max <= 1.5) { } 0 0 0
35 0 $unit = "ns";
36 0 $factor = 1e9;
37 } elsif ($max <= 1.5e-3) {
38 0 $unit = "\x{03bc}s"; # XXX enable utf
39 0 $factor = 1e6;
40 } elsif ($max <= 1.5) {
41 0 $unit = "ms";
42 0 $factor = 1e3;
43 }
44  
45 0 $envres->[3]{'func.time_factor'} = $factor;
46  
47 0 ▶ if ($unit) {
Branch: 1 branch
BranchTrueFalseTotal
if ($unit) 0 0 0
48 0 for my $rit (@{$envres->[2]}) {
49 0 $rit->{time} *= $factor;
50 0 ▶ if (exists $rit->{mod_overhead_time}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rit->{"mod_overhead_time"}) 0 0 0
51 0 $rit->{mod_overhead_time} *= $factor;
52 }
53 }
54  
55 0 ▶ $envres->[3]{'table.field_units'} //= [];
Condition0%0/2
$envres->[3]{"table.field_units"} //= []
l!l
00
MC/DC0%0/1
$envres->[3]{"table.field_units"} //= []
$envres->[3]{"table.field_units"}
Truth table0%0/2
A
A= $envres->[3]{"table.field_units"}
Aresult
11
00
56 0 my $fus = $envres->[3]{'table.field_units'};
57  
58 0 my $i = -1;
59 0 for my $f (@{$envres->[3]{'table.fields'}}) {
60 0 $i++;
61 0 ▶ if ($f =~ /\A(time|mod_overhead_time)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f =~ /\A(time|mod_overhead_time)\z/) 0 0 0
62 0 $fus->[$i] = $unit;
63 }
64 }
65 }
66 }
67  
68 1 1;
69 # ABSTRACT: Scale time to make it convenient
70  
71 __END__
« Bencher/Formatter/RoundNumbers.pm ↑ Summary Bencher/Formatter/RenderAsBenchmarkPm.pm »