Bencher/Formatter/RenderAsBenchmarkPm.pm

filter: Statementstmt 37.0% 20 / 54 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 34.7% 25 / 72 CC 9 SCAR 40.6
CC
9
Cov
32%
render_result
90.0
BEGIN
1.0
BEGIN
1.0
CRAP 58.2
« Bencher/Formatter/ScaleTime.pm ↑ Summary Bencher/Formatter/Sort.pm »
1 package Bencher::Formatter::RenderAsBenchmarkPm;
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  
7 1 ▶use parent qw(Bencher::Formatter);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Role::Tiny::With;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 with 'Bencher::Role::ResultRenderer';
11  
12 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
13 1 our $DATE = '2023-07-08'; # DATE
14 1 our $DIST = 'Bencher-Backend'; # DIST
15 1 our $VERSION = '1.063'; # VERSION
16  
17 0 ▶sub render_result {
Subroutine render_result: not called CC=9 SCAR=45.0
Pod undocumented
18 0 require Text::Table::More;
19  
20 0 my ($self, $envres) = @_;
21  
22 # because underscored keys were removed; we want _succint_name back.
23 0 my $items = $envres->[2];
24 0 Bencher::Backend::_set_item_names($items);
25 0 my @item_names;
26 my %legends; # key = succinct_name
27 0 for my $it (@$items) {
28 0 push @item_names, $it->{_succinct_name};
29 $legends{$it->{_succinct_name}} =
30 0 ▶ join(" ", map {"$_=$it->{$_}"} grep { !/^_/ && !/^(errors|pct_|rate|samples|time)/ } sort keys %$it);
Condition0%0/3
/^_/ || /^(errors|pct_|rate|samples|time)/
l!l&&r!l&&!r
000
MC/DC0%0/2
/^_/ || /^(errors|pct_|rate|samples|time)/
/^_/ /^(errors|pct_|rate|samples|time)/
Truth table0%0/3
A || B
A= /^_/B= /^(errors|pct_|rate|samples|time)/
ABresult
1X1
011
000
31 }
32  
33 0 my @rows;
34 0 push @rows, [
35 # column names
36 "", # item name
37 "Rate",
38 @item_names,
39 ];
40 0 for my $i (0..$#{$items}) {
41 0 my $it = $items->[$i];
42 push @rows, [
43 $it->{_succinct_name},
44 0 ▶ (defined($it->{rate}) ? "$it->{rate}/s" : sprintf("%.1f/s", 1000/$it->{time})),
Branch: 1 branch
BranchTrueFalseTotal
defined $it->{'rate'} ? : 0 0 0
45 ];
46 0 for my $j (0..$#{$items}) {
47 0 my $pct;
48 0 ▶ if ($i == $j) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $j) { } 0 0 0
49 0 $pct = "--";
50 } else {
51 0 ▶ if ($items->[$j]{time} < $it->{time}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($items->[$j]{'time'} < $it->{'time'}) { } 0 0 0
52 # item i is slower than item j by N percent
53 0 $pct = -(1 - $items->[$j]{time} / $it->{time}) * 100;
54 } else {
55 # item i is faster than item j by N percent
56 0 $pct = ($items->[$j]{time} / $it->{time} -1) * 100;
57 }
58 0 $pct = sprintf("%d%%", $pct);
59 }
60 0 push @{ $rows[-1] }, $pct;
61 }
62 }
63  
64 0 my $rres = ''; # render result
65  
66 0 $rres .= Text::Table::More::table(
67 rows => \@rows,
68 border_style=>'ASCII::None',
69 align => 'right',
70 col_attrs => [
71 [0, {align=>'left'}],
72 ],
73 );
74 0 $rres .= "\n";
75 0 $rres .= "Legends:\n";
76 0 for (sort keys %legends) {
77 0 $rres .= " " . $_ . ": " . $legends{$_} . "\n";
78 }
79  
80 0 $rres;
81 }
82  
83 1 1;
84 # ABSTRACT: Scale time to make it convenient
85  
86 __END__
« Bencher/Formatter/ScaleTime.pm ↑ Summary Bencher/Formatter/Sort.pm »