| 1 | package Dumbbench; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Time::HiRes (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | our $VERSION = '0.505'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 3 | require Dumbbench::Result; | |||||||||||||||||||||||||||
| 10 | 3 | require Dumbbench::Stats; | |||||||||||||||||||||||||||
| 11 | 3 | require Dumbbench::Instance; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Params::Util '_INSTANCE'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use Class::XSAccessor { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 3 | getters => [qw( | |||||||||||||||||||||||||||
| 17 | target_rel_precision | ||||||||||||||||||||||||||||
| 18 | target_abs_precision | ||||||||||||||||||||||||||||
| 19 | initial_runs | ||||||||||||||||||||||||||||
| 20 | max_iterations | ||||||||||||||||||||||||||||
| 21 | variability_measure | ||||||||||||||||||||||||||||
| 22 | started | ||||||||||||||||||||||||||||
| 23 | outlier_rejection | ||||||||||||||||||||||||||||
| 24 | subtract_dry_run | ||||||||||||||||||||||||||||
| 25 | )], | ||||||||||||||||||||||||||||
| 26 | accessors => [qw(verbosity)], | ||||||||||||||||||||||||||||
| 27 | 3 | }; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=25.7
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 3 | my $proto = shift; | |||||||||||||||||||||||||||
| 32 | 3 | ▶ | my $class = ref($proto)||$proto; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 33 | 3 | my $self; | |||||||||||||||||||||||||||
| 34 | 3 | ▶ | if (not ref($proto)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 3 | $self = bless { | |||||||||||||||||||||||||||
| 36 | verbosity => 0, | ||||||||||||||||||||||||||||
| 37 | target_rel_precision => 0.05, | ||||||||||||||||||||||||||||
| 38 | target_abs_precision => 0, | ||||||||||||||||||||||||||||
| 39 | initial_runs => 20, | ||||||||||||||||||||||||||||
| 40 | max_iterations => 10000, | ||||||||||||||||||||||||||||
| 41 | variability_measure => 'mad', | ||||||||||||||||||||||||||||
| 42 | instances => [], | ||||||||||||||||||||||||||||
| 43 | started => 0, | ||||||||||||||||||||||||||||
| 44 | outlier_rejection => 3, | ||||||||||||||||||||||||||||
| 45 | subtract_dry_run => 1, | ||||||||||||||||||||||||||||
| 46 | @_, | ||||||||||||||||||||||||||||
| 47 | } => $class; | ||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | else { | ||||||||||||||||||||||||||||
| 50 | 0 | $self = bless {%$proto, @_} => $class; | |||||||||||||||||||||||||||
| 51 | 0 | my @inst = $self->instances; | |||||||||||||||||||||||||||
| 52 | 0 | $self->{instances} = []; | |||||||||||||||||||||||||||
| 53 | 0 | foreach my $instance (@inst) { | |||||||||||||||||||||||||||
| 54 | 0 | push @{$self->{instances}}, $instance->new; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 3 | ▶ | if ($self->target_abs_precision <= 0 and $self->target_rel_precision <= 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->target_abs_precision <= 0 and $self->target_rel_precision <= 0
MC/DC0%0/2
$self->target_abs_precision <= 0 and $self->target_rel_precision <= 0
$self->target_abs_precision <= 0
$self->target_rel_precision <= 0
Truth table33%1/3
A and B
A= $self->target_abs_precision <= 0B= $self->target_rel_precision <= 0
| |||||||||||||||||||||||||||||
| 59 | 0 | Carp::croak("Need either target_rel_precision or target_abs_precision > 0"); | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | 3 | ▶ | if ($self->initial_runs < 6) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 3 | Carp::carp("Number of initial runs is very small (<6). Precision will be off."); | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 3 | return $self; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 4 | ▶ | sub add_instances { | ||||||||||||||||||||||||||
|
Subroutine
add_instances: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||||||||||||||||||||
| 69 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 4 | ▶ | if ($self->started) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 0 | Carp::croak("Can't add instances after the benchmark has been started"); | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | 4 | foreach my $instance (@_) { | |||||||||||||||||||||||||||
| 75 | 4 | ▶ | if (not _INSTANCE($instance, 'Dumbbench::Instance')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 0 | Carp::croak("Argument to add_instances is not a Dumbbench::Instance"); | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | 4 | push @{$self->{instances}}, @_; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 10 | ▶ | sub instances { | ||||||||||||||||||||||||||
|
Subroutine
instances: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | 10 | my $self = shift; | |||||||||||||||||||||||||||
| 84 | 10 | return @{$self->{instances}}; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 3 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||
| 88 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 89 | 3 | ▶ | Carp::croak("Can't re-run same benchmark instance") if $self->started; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 3 | ▶ | $self->dry_run_timings if $self->subtract_dry_run; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 3 | $self->run_timings; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 3 | ▶ | sub run_timings { | ||||||||||||||||||||||||||
|
Subroutine
run_timings: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 95 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 96 | 3 | $self->{started} = 1; | |||||||||||||||||||||||||||
| 97 | 3 | foreach my $instance ($self->instances) { | |||||||||||||||||||||||||||
| 98 | 4 | ▶ | next if $instance->result; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 4 | $self->_run($instance); | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 3 | ▶ | sub dry_run_timings { | ||||||||||||||||||||||||||
|
Subroutine
dry_run_timings: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 104 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 105 | 3 | $self->{started} = 1; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 3 | foreach my $instance ($self->instances) { | |||||||||||||||||||||||||||
| 108 | 4 | ▶ | next if $instance->dry_result; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 4 | $self->_run($instance, 'dry'); | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 8 | ▶ | sub _run { | ||||||||||||||||||||||||||
|
Subroutine
_run: called CC=32 SCAR=39.0
| |||||||||||||||||||||||||||||
| 114 | 8 | my $self = shift; | |||||||||||||||||||||||||||
| 115 | 8 | my $instance = shift; | |||||||||||||||||||||||||||
| 116 | 8 | my $dry = shift; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 8 | my $name = $instance->_name_prefix; | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | # for overriding in case of dry-run mode | ||||||||||||||||||||||||||||
| 121 | 8 | ▶ | my $V = $self->verbosity || 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->verbosity || 0
MC/DC0%0/1
$self->verbosity || 0
$self->verbosity
Truth table50%1/2
A
A= $self->verbosity
| |||||||||||||||||||||||||||||
| 122 | 8 | my $initial_timings = $self->initial_runs; | |||||||||||||||||||||||||||
| 123 | 8 | my $abs_precision = $self->target_abs_precision; | |||||||||||||||||||||||||||
| 124 | 8 | my $rel_precision = $self->target_rel_precision; | |||||||||||||||||||||||||||
| 125 | 8 | my $max_iterations = $self->max_iterations; | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 8 | ▶ | if ($dry) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 4 | ▶ | $V--; $V = 0 if $V < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | 4 | $initial_timings *= 5; | |||||||||||||||||||||||||||
| 130 | 4 | $abs_precision = 0; | |||||||||||||||||||||||||||
| 131 | 4 | $rel_precision /= 2; | |||||||||||||||||||||||||||
| 132 | 4 | $max_iterations *= 10; | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 8 | ▶ | print "${name}Running initial timing for warming up the cache...\n" if $V; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 8 | ▶ | if ($dry) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | # be generous, this is fast | ||||||||||||||||||||||||||||
| 138 | 4 | $instance->single_dry_run() for 1..3; | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | else { | ||||||||||||||||||||||||||||
| 141 | 4 | $instance->single_run(); | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 8 | my @timings; | |||||||||||||||||||||||||||
| 145 | 8 | ▶ | print "${name}Running $initial_timings initial timings...\n" if $V; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | 8 | foreach (1..$initial_timings) { | |||||||||||||||||||||||||||
| 147 | 24 | ▶ | print "${name}Running timing $_...\n" if $V > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | 24 | ▶ | push @timings, ($dry ? $instance->single_dry_run() : $instance->single_run()); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 8 | ▶ | print "${name}Iterating until target precision reached...\n" if $V; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 8 | my $stats = Dumbbench::Stats->new(data => \@timings); | |||||||||||||||||||||||||||
| 154 | 8 | my $sigma; | |||||||||||||||||||||||||||
| 155 | my $mean; | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | #My mental model for the distribution was Gauss+outliers. | ||||||||||||||||||||||||||||
| 158 | #If my expectation is correct, the following algorithm should produce a reasonable EV +/- uncertainty: | ||||||||||||||||||||||||||||
| 159 | #1) Calc. median of the whole distribution. | ||||||||||||||||||||||||||||
| 160 | #2) Calculate the median-absolute deviation from the whole distribution (MAD, see wikipedia). It needs rescaling to become a measure of variability that is robust against outliers. | ||||||||||||||||||||||||||||
| 161 | #(The MAD will be our initial guess for a "sigma") | ||||||||||||||||||||||||||||
| 162 | #3) Reject the samples that are outside $median +/- $n*$MAD. | ||||||||||||||||||||||||||||
| 163 | #I was expecting several high outliers but few lows. An ordinary truncated mean or the like would be unsuitable for removing the outliers in such a case since you'd get a significant upward bias of your EV. | ||||||||||||||||||||||||||||
| 164 | #By using the median as the initial guess, we keep the initial bias to a minimum. The MAD will be similarly unaffected by outliers AND the asymmetry. | ||||||||||||||||||||||||||||
| 165 | #Thus cutting the tails won't blow up the bias too strongly (hopefully). | ||||||||||||||||||||||||||||
| 166 | #4) Calculate mean & MAD/sqrt($n) of the remaining distribution. These are our EV and uncertainty on the mean. | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 8 | my $n_good = 0; | |||||||||||||||||||||||||||
| 169 | 8 | my $variability_measure = $self->variability_measure; | |||||||||||||||||||||||||||
| 170 | 8 | while (1) { | |||||||||||||||||||||||||||
| 171 | 20 | my ($good, $outliers) = $stats->filter_outliers( | |||||||||||||||||||||||||||
| 172 | variability_measure => $variability_measure, | ||||||||||||||||||||||||||||
| 173 | nsigma_outliers => $self->outlier_rejection, | ||||||||||||||||||||||||||||
| 174 | ); | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 20 | $n_good = @$good; | |||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 20 | ▶ | if (not $n_good and @timings >= $max_iterations) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $n_good and @timings >= $max_iterations
MC/DC0%0/2
not $n_good and @timings >= $max_iterations
not $n_good
@timings >= $max_iterations
Truth table33%1/3
not(A) and B
A= not $n_goodB= @timings >= $max_iterations
| |||||||||||||||||||||||||||||
| 179 | 0 | $mean = 0; $sigma = 0; | |||||||||||||||||||||||||||
| 180 | 0 | last; | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 20 | ▶ | if ($n_good) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | 20 | my $new_stats = Dumbbench::Stats->new(data => $good); | |||||||||||||||||||||||||||
| 185 | 20 | $sigma = $new_stats->$variability_measure() / sqrt($n_good); | |||||||||||||||||||||||||||
| 186 | 20 | $mean = $new_stats->mean(); | |||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | # stop condition | ||||||||||||||||||||||||||||
| 189 | 20 | my $need_iter = 0; | |||||||||||||||||||||||||||
| 190 | 20 | ▶ | if ($rel_precision > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 191 | 20 | my $rel = $sigma/$mean; | |||||||||||||||||||||||||||
| 192 | 20 | ▶ | print "${name}Reached relative precision $rel (neeed $rel_precision).\n" if $V > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | 20 | ▶ | $need_iter++ if $rel > $rel_precision; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | 20 | ▶ | if ($abs_precision > 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | 0 | ▶ | print "${name}Reached absolute precision $sigma (neeed $abs_precision).\n" if $V > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | 0 | ▶ | $need_iter++ if $sigma > $abs_precision; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | 20 | ▶ | if ($n_good < $initial_timings) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | 8 | $need_iter++; | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | 20 | ▶ | last if not $need_iter or @timings >= $max_iterations; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $need_iter or @timings >= $max_iterations
MC/DC50%1/2
not $need_iter or @timings >= $max_iterations
not $need_iter
@timings >= $max_iterations
Truth table66%2/3
not(A) or B
A= not $need_iterB= @timings >= $max_iterations
| |||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | # progressively run more new timings in one go. Otherwise, | ||||||||||||||||||||||||||||
| 206 | # we start to stall on the O(n*log(n)) complexity of the median. | ||||||||||||||||||||||||||||
| 207 | 12 | my $n = List::Util::min( $max_iterations - @timings, List::Util::max(1, @timings*0.05) ); | |||||||||||||||||||||||||||
| 208 | 12 | ▶ | push @timings, ($dry ? $instance->single_dry_run() : $instance->single_run()) for 1..$n; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 209 | } # end while more data required | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 8 | ▶ | if (@timings >= $max_iterations and not $dry) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@timings >= $max_iterations and not $dry
MC/DC0%0/2
@timings >= $max_iterations and not $dry
@timings >= $max_iterations
not $dry
Truth table33%1/3
A and not(B)
A= @timings >= $max_iterationsB= not $dry
| |||||||||||||||||||||||||||||
| 212 | 0 | print "${name}Reached maximum number of iterations. Stopping. Precision not reached.\n"; | |||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | # rescale sigma | ||||||||||||||||||||||||||||
| 216 | # This is necessary since by cutting everything outside of n-sigma, | ||||||||||||||||||||||||||||
| 217 | # we artificially reduce the variability of the main distribution. | ||||||||||||||||||||||||||||
| 218 | 8 | ▶ | if ($self->outlier_rejection) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 219 | # TODO implement | ||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 8 | my $result = Dumbbench::Result->new( | |||||||||||||||||||||||||||
| 223 | timing => $mean, | ||||||||||||||||||||||||||||
| 224 | uncertainty => $sigma, | ||||||||||||||||||||||||||||
| 225 | nsamples => $n_good, | ||||||||||||||||||||||||||||
| 226 | ); | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | 8 | ▶ | if ($dry) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 229 | 4 | $instance->{dry_timings} = \@timings; | |||||||||||||||||||||||||||
| 230 | 4 | $instance->dry_result($result); | |||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||
| 232 | else { | ||||||||||||||||||||||||||||
| 233 | 4 | $instance->{timings} = \@timings; | |||||||||||||||||||||||||||
| 234 | 4 | ▶ | $result -= $instance->dry_result | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $instance->dry_result and $self->subtract_dry_run
MC/DC0%0/2
defined $instance->dry_result and $self->subtract_dry_run
defined $instance->dry_result
$self->subtract_dry_run
Truth table33%1/3
A and B
A= defined $instance->dry_resultB= $self->subtract_dry_run
| |||||||||||||||||||||||||||||
| 235 | if defined $instance->dry_result and $self->subtract_dry_run; | ||||||||||||||||||||||||||||
| 236 | 4 | $instance->result($result); | |||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | 0 | ▶ | sub report { | ||||||||||||||||||||||||||
|
Subroutine
report: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 241 | 0 | my ( $self, $raw, $options ) = @_; | |||||||||||||||||||||||||||
| 242 | 0 | ▶ | $options ||= {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$options ||= {}
MC/DC0%0/1
$options ||= {}
$options
Truth table0%0/2
A
A= $options
| |||||||||||||||||||||||||||||
| 243 | 0 | ▶ | Carp::carp( "The second option to report was not a hash ref" ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 244 | unless ref $options eq ref {}; | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 0 | foreach my $instance ($self->instances) { | |||||||||||||||||||||||||||
| 247 | 0 | my $result = $instance->result; | |||||||||||||||||||||||||||
| 248 | 0 | ▶ | my $result_str = ($options->{float}) ? unscientific_notation($result) : "$result"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | 0 | ▶ | if (not $raw) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 251 | 0 | my $mean = $result->raw_number; | |||||||||||||||||||||||||||
| 252 | 0 | my $sigma = $result->raw_error->[0]; | |||||||||||||||||||||||||||
| 253 | 0 | my $name = $instance->_name_prefix; | |||||||||||||||||||||||||||
| 254 | printf( | ||||||||||||||||||||||||||||
| 255 | "%sRan %u iterations (%u outliers).\n", | ||||||||||||||||||||||||||||
| 256 | $name, | ||||||||||||||||||||||||||||
| 257 | 0 | scalar(@{$instance->timings}), | |||||||||||||||||||||||||||
| 258 | 0 | scalar(@{$instance->timings})-$result->nsamples | |||||||||||||||||||||||||||
| 259 | ); | ||||||||||||||||||||||||||||
| 260 | 0 | printf( | |||||||||||||||||||||||||||
| 261 | "%sRounded run time per iteration (seconds): %s (%.1f%%)\n", | ||||||||||||||||||||||||||||
| 262 | $name, | ||||||||||||||||||||||||||||
| 263 | $result_str, | ||||||||||||||||||||||||||||
| 264 | $sigma/$mean*100 | ||||||||||||||||||||||||||||
| 265 | ); | ||||||||||||||||||||||||||||
| 266 | 0 | ▶ | if ($self->verbosity) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 267 | 0 | printf("%sRaw: $mean +/- $sigma\n", $name); | |||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||
| 270 | else { | ||||||||||||||||||||||||||||
| 271 | 0 | print $result_str, "\n"; | |||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | 0 | ▶ | sub box_plot { | ||||||||||||||||||||||||||
|
Subroutine
box_plot: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 277 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 278 | 0 | require Dumbbench::BoxPlot; | |||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | 0 | return Dumbbench::BoxPlot->new($self); | |||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | 0 | ▶ | sub unscientific_notation { | ||||||||||||||||||||||||||
|
Subroutine
unscientific_notation: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 284 | 0 | sprintf( "%f %s %f", split( / /, $_[0] ) ); | |||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | 3 | 1; | |||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | __END__ | ||||||||||||||||||||||||||||