| 1 | 2 | ▶ | use 5.010; # Perl 5.10+ needed for PDL | ||||||||||||||||||||||||||||||||||||||||
|
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.003-2-gf405410 | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | our $AUTHORITY = 'cpan:SCHWIGON'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | # ABSTRACT: Evaluation support for BenchmarkAnything data | ||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | $BenchmarkAnything::Evaluations::VERSION = '0.004'; | |||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use PDL::Core; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use PDL::Stats; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use PDL::Ufunc; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | sub multi_point_stats | ||||||||||||||||||||||||||||||||||||||||||
| 16 | { | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 12 | ▶ | my ($values) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
multi_point_stats: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 12 | my $data = pdl(@$values); | |||||||||||||||||||||||||||||||||||||||||
| 20 | 12 | my $avg = average($data); | |||||||||||||||||||||||||||||||||||||||||
| 21 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 12 | 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 | 1 | ▶ | my ($chartlines, $options) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
transform_chartlines: called CC=42 SCAR=48.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | my $x_key = $options->{x_key}; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | my $x_type = $options->{x_type}; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | my $y_key = $options->{y_key}; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | my $y_type = $options->{y_type}; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | my $aggregation = $options->{aggregation}; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | my $verbose = $options->{verbose}; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | my $debug = $options->{debug}; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | my $dropnull = $options->{dropnull}; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | 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 | 1 | my @titles; | |||||||||||||||||||||||||||||||||||||||||
| 52 | my %VALUES; | ||||||||||||||||||||||||||||||||||||||||||
| 53 | CHARTLINE: | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | foreach my $chartline (@$chartlines) | |||||||||||||||||||||||||||||||||||||||||
| 55 | { | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 3 | my $title = $chartline->{title}; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 3 | my $results = $chartline->{results}; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 3 | my $NAME = $results->[0]{NAME}; | |||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | # skip typical empty results | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 3 | ▶ | if (not @$results or (@$results == 1 and not $results->[0]{NAME})) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not @$results or @$results == 1 and not $results->[0]{"NAME"}
@$results == 1 and not $results->[0]{"NAME"}
MC/DC0%0/3
not @$results or @$results == 1 and not $results->[0]{"NAME"}
not @$results
@$results == 1
not $results->[0]{"NAME"}
Truth table0%0/4
not(A) or B and not(C)
A= not @$resultsB= @$results == 1C= not $results->[0]{"NAME"}
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | { | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | print STDERR "benchmarkanything: transform_chartlines: ignore empty chartline '$title'\n" if $verbose; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | next CHARTLINE; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 3 | push @titles, $title; | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 3 | my $rawline = sprintf("* %-20s - %-40s\n", $title, $NAME); | |||||||||||||||||||||||||||||||||||||||||
| 69 | 3 | ▶ | print STDERR $rawline if $verbose; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 3 | $rawnumbers.=$rawline; | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 3 | ▶ | print STDERR " VALUE_IDs: ".join(",", map {$_->{VALUE_ID}} @$results)."\n" if $debug; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | POINT: | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 3 | foreach my $point (@$results) | |||||||||||||||||||||||||||||||||||||||||
| 76 | { | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 12 | my $x = $point->{$x_key}; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 12 | my $y = $point->{$y_key}; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 12 | ▶ | if (not defined $x) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | { | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | require Data::Dumper; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | print STDERR "benchmarkanything: transform_chartlines: chartline '$title': ignore data point (missing key '$x_key'): ".Data::Dumper::Dumper($results) if $verbose; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | next POINT; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 12 | push @{$VALUES{$title}{$x}{values}}, $y; # maybe multiple for same X - average them later | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | # statistical aggregations of multi points | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | foreach my $title (keys %VALUES) | |||||||||||||||||||||||||||||||||||||||||
| 91 | { | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 3 | foreach my $x (keys %{$VALUES{$title}}) | |||||||||||||||||||||||||||||||||||||||||
| 93 | { | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 12 | my $multi_point_values = $VALUES{$title}{$x}{values}; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 12 | $VALUES{$title}{$x}{stats} = multi_point_stats($multi_point_values); | |||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | # find out all available x-values from all chartlines | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | my %all_x; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | foreach my $title (keys %VALUES) | |||||||||||||||||||||||||||||||||||||||||
| 102 | { | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 3 | foreach my $x (keys %{$VALUES{$title}}) | |||||||||||||||||||||||||||||||||||||||||
| 104 | { | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 12 | $all_x{$x} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 1 | my @all_x = keys %all_x; | |||||||||||||||||||||||||||||||||||||||||
| 109 | @all_x = | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 4 | ▶ | $x_type eq 'version' ? sort {version->parse($a) <=> version->parse($b)} @all_x | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | : $x_type eq 'numeric' ? sort {$a <=> $b} @all_x | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | : $x_type eq 'string' ? sort {$a cmp $b} @all_x | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 1 | ▶ | : $x_type eq 'date' ? sort { die "TODO: sort by date" ; $a cmp $b} @all_x | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | : @all_x; | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | # drop complete chartlines if it has gaps on versions that the other chartlines provide values | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | my %clean_chartlines; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 1 | ▶ | if ($dropnull) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | foreach my $title (keys %VALUES) { | |||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | my $ok = 1; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | foreach my $x (@all_x) { | |||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if (not @{$VALUES{$title}{$x}{values} || []}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | print STDERR "skip: $title (missing values for $x)\n" if $verbose; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $ok = 0; | |||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | if ($ok) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $clean_chartlines{$title} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | print STDERR "okay: $title\n" if $verbose; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | # intermediate debug output | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | foreach my $title (keys %VALUES) | |||||||||||||||||||||||||||||||||||||||||
| 136 | { | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 3 | foreach my $x (keys %{$VALUES{$title}}) | |||||||||||||||||||||||||||||||||||||||||
| 138 | { | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 12 | ▶ | my $count = scalar @{$VALUES{$title}{$x}{values} || []} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
scalar @{$VALUES{$title}{$x}{'values'} or [];} || 0
MC/DC0%0/1
scalar @{$VALUES{$title}{$x}{'values'} or [];} || 0
scalar @{$VALUES{$title}{$x}{'values'} or [];}
Truth table50%1/2
A
A= scalar @{$VALUES{$title}{$x}{'values'} or [];}
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | 12 | ▶ | next if not $count; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 12 | my $avg = $VALUES{$title}{$x}{stats}{avg}; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 12 | my $stdv = $VALUES{$title}{$x}{stats}{stdv}; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 12 | my $ci95l = $VALUES{$title}{$x}{stats}{ci_95_lower}; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 12 | my $ci95u = $VALUES{$title}{$x}{stats}{ci_95_upper}; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 12 | 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 | 12 | $rawnumbers .= $rawline; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 12 | ▶ | print STDERR $rawline if $verbose; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | # result data structure, as needed per chart type | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | my @RESULTMATRIX; | |||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | ▶ | @titles = grep { !$dropnull or $clean_chartlines{$_} } @titles; # dropnull | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | ▶ | for (my $i=0; $i<@all_x; $i++) # rows | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | { | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 4 | my $x = $all_x[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 4 | ▶ | for (my $j=0; $j<@titles; $j++) # columns | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | { | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 12 | my $title = $titles[$j]; | |||||||||||||||||||||||||||||||||||||||||
| 162 | 12 | my $value = $VALUES{$title}{$x}{stats}{$aggregation}; | |||||||||||||||||||||||||||||||||||||||||
| 163 | # stringify to unbless from PDL, then numify for type-aware JSON | ||||||||||||||||||||||||||||||||||||||||||
| 164 | 12 | ▶ | $value = $value ? (0+sprintf("%6.2f", $value)) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 12 | ▶ | $RESULTMATRIX[0] [0] = $x_key if $i == 0 && $j == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$i == 0 and $j == 0
MC/DC100%2/2
$i == 0 and $j == 0
$i == 0
$j == 0
Truth table100%3/3
A and B
A= $i == 0B= $j == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 12 | ▶ | $RESULTMATRIX[0] [$j+1] = $title if $i == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 12 | ▶ | $RESULTMATRIX[$i+1] [0] = $x if $j == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 12 | $RESULTMATRIX[$i+1] [$j+1] = $value; | |||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 1 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | return (\@RESULTMATRIX, $rawnumbers); | |||||||||||||||||||||||||||||||||||||||||
| 174 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 1 | return \@RESULTMATRIX; | |||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | __END__ | ||||||||||||||||||||||||||||||||||||||||||