blib/lib/BenchmarkAnything/Evaluations.pm

filter: Statementstmt 81.8% 9 / 11 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 86.6% 13 / 15 CC 1 SCAR 0.7
CC
1
Cov
82%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1 2 ▶use 5.010; # Perl 5.10+ needed for PDL/PDLA
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 package BenchmarkAnything::Evaluations;
5 # git description: v0.002-3-g453b389
6  
7 our $AUTHORITY = 'cpan:SCHWIGON';
8 # ABSTRACT: Evaluation support for BenchmarkAnything data
9 $BenchmarkAnything::Evaluations::VERSION = '0.003';
10 2 ▶use PDLA::Core;
Subroutine BEGIN: called CC=1 SCAR=2.6
11 use PDLA::Stats;
12 use PDLA::Ufunc;
13  
14  
15 sub multi_point_stats
16 {
17 my ($values) = @_;
18  
19 my $data = pdl(@$values);
20 my $avg = average($data);
21 return {
22 avg => sclr($avg),
23 stdv => stdv($data),
24 min => min($data),
25 max => max($data),
26 ci_95_lower => $avg - 1.96 * se($data),
27 ci_95_upper => $avg + 1.96 * se($data),
28 };
29 }
30  
31  
32 sub transform_chartlines
33 {
34 my ($chartlines, $options) = @_;
35  
36 my $x_key = $options->{x_key};
37 my $x_type = $options->{x_type};
38 my $y_key = $options->{y_key};
39 my $y_type = $options->{y_type};
40 my $aggregation = $options->{aggregation};
41 my $verbose = $options->{verbose};
42 my $debug = $options->{debug};
43 my $dropnull = $options->{dropnull};
44 my $rawnumbers = "";
45  
46 # from all chartlines collect values into buckets for the dimensions we need
47 #
48 # chartline = title
49 # x = perlconfig_version
50 # y = VALUE
51 my @titles;
52 my %VALUES;
53 CHARTLINE:
54 foreach my $chartline (@$chartlines)
55 {
56 my $title = $chartline->{title};
57 my $results = $chartline->{results};
58 my $NAME = $results->[0]{NAME};
59  
60 # skip typical empty results
61 if (not @$results or (@$results == 1 and not $results->[0]{NAME}))
62 {
63 print STDERR "benchmarkanything: transform_chartlines: ignore empty chartline '$title'\n" if $verbose;
64 next CHARTLINE;
65 }
66 push @titles, $title;
67  
68 my $rawline = sprintf("* %-20s - %-40s\n", $title, $NAME);
69 print STDERR $rawline if $verbose;
70 $rawnumbers.=$rawline;
71  
72 print STDERR " VALUE_IDs: ".join(",", map {$_->{VALUE_ID}} @$results)."\n" if $debug;
73  
74 POINT:
75 foreach my $point (@$results)
76 {
77 my $x = $point->{$x_key};
78 my $y = $point->{$y_key};
79 if (not defined $x)
80 {
81 require Data::Dumper;
82 print STDERR "benchmarkanything: transform_chartlines: chartline '$title': ignore data point (missing key '$x_key'): ".Data::Dumper::Dumper($results) if $verbose;
83 next POINT;
84 }
85 push @{$VALUES{$title}{$x}{values}}, $y; # maybe multiple for same X - average them later
86 }
87 }
88  
89 # statistical aggregations of multi points
90 foreach my $title (keys %VALUES)
91 {
92 foreach my $x (keys %{$VALUES{$title}})
93 {
94 my $multi_point_values = $VALUES{$title}{$x}{values};
95 $VALUES{$title}{$x}{stats} = multi_point_stats($multi_point_values);
96 }
97 }
98  
99 # find out all available x-values from all chartlines
100 my %all_x;
101 foreach my $title (keys %VALUES)
102 {
103 foreach my $x (keys %{$VALUES{$title}})
104 {
105 $all_x{$x} = 1;
106 }
107 }
108 my @all_x = keys %all_x;
109 @all_x =
110 $x_type eq 'version' ? sort {version->parse($a) <=> version->parse($b)} @all_x
111 : $x_type eq 'numeric' ? sort {$a <=> $b} @all_x
112 : $x_type eq 'string' ? sort {$a cmp $b} @all_x
113 : $x_type eq 'date' ? sort { die "TODO: sort by date" ; $a cmp $b} @all_x
114 : @all_x;
115  
116 # drop complete chartlines if it has gaps on versions that the other chartlines provide values
117 my %clean_chartlines;
118 if ($dropnull) {
119 foreach my $title (keys %VALUES) {
120 my $ok = 1;
121 foreach my $x (@all_x) {
122 if (not @{$VALUES{$title}{$x}{values} || []}) {
123 print STDERR "skip: $title (missing values for $x)\n" if $verbose;
124 $ok = 0;
125 }
126 }
127 if ($ok) {
128 $clean_chartlines{$title} = 1;
129 print STDERR "okay: $title\n" if $verbose;
130 }
131 }
132 }
133  
134 # intermediate debug output
135 foreach my $title (keys %VALUES)
136 {
137 foreach my $x (keys %{$VALUES{$title}})
138 {
139 my $count = scalar @{$VALUES{$title}{$x}{values} || []} || 0;
140 next if not $count;
141 my $avg = $VALUES{$title}{$x}{stats}{avg};
142 my $stdv = $VALUES{$title}{$x}{stats}{stdv};
143 my $ci95l = $VALUES{$title}{$x}{stats}{ci_95_lower};
144 my $ci95u = $VALUES{$title}{$x}{stats}{ci_95_upper};
145 my $rawline = sprintf(" %-20s . %-7s . (ci95l..avg..ci95u) = (%2.2f .. %2.2f .. %2.2f) +- stdv %5.2f (%3d points)\n", $title, $x, $ci95l, $avg, $ci95u, $stdv, $count);
146 $rawnumbers .= $rawline;
147 print STDERR $rawline if $verbose;
148 }
149 }
150  
151 # result data structure, as needed per chart type
152 my @RESULTMATRIX;
153  
154 @titles = grep { !$dropnull or $clean_chartlines{$_} } @titles; # dropnull
155  
156 for (my $i=0; $i<@all_x; $i++) # rows
157 {
158 my $x = $all_x[$i];
159 for (my $j=0; $j<@titles; $j++) # columns
160 {
161 my $title = $titles[$j];
162 my $value = $VALUES{$title}{$x}{stats}{$aggregation};
163 # stringify to unbless from PDL, then numify for type-aware JSON
164 $value = $value ? (0+sprintf("%6.2f", $value)) : undef;
165 $RESULTMATRIX[0] [0] = $x_key if $i == 0 && $j == 0;
166 $RESULTMATRIX[0] [$j+1] = $title if $i == 0;
167 $RESULTMATRIX[$i+1] [0] = $x if $j == 0;
168 $RESULTMATRIX[$i+1] [$j+1] = $value;
169 }
170 }
171  
172 if (wantarray) {
173 return (\@RESULTMATRIX, $rawnumbers);
174 } else {
175 return \@RESULTMATRIX;
176 }
177 }
178  
179 1;
180  
181 __END__
↑ Summary