blib/lib/Benchmark/MCE.pm

filter: Statementstmt 100% 280 / 280 Branchbran 94.1% 162 / 172 Conditioncond 78.9% 75 / 95 MC/DCmcdc 56.3% 31 / 55 Subroutinesub 100% 28 / 28 Podpod 100% 4 / 4 totaltotal 91.4% 580 / 634 CC 132 SCAR 27.7
CC
132
Cov
95%
calc_scalability
27.0
system_identity
26.1
_init_options
25.0
CRAP 15.9
↑ Summary
1 package Benchmark::MCE;
2  
3 21 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 21 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 21 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 21 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 21 ▶use List::Util qw(min max sum);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 21 ▶use Time::HiRes qw(CLOCK_MONOTONIC);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 21 ▶use MCE::Loop;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 21 ▶use System::CPU;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 21 ▶use System::Info;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 21 our $VERSION = '1.03';
16 21 our @EXPORT = qw(system_identity suite_run calc_scalability suite_calc);
17 21 ▶our $MONO_CLOCK = $^O !~ /win/i || $Time::HiRes::VERSION >= 1.9764;
Condition33%1/3
!($^O =~ /win/i) || $Time::HiRes::VERSION >= 1.9764
l!l&&r!l&&!r
2100
MC/DC0%0/2
!($^O =~ /win/i) || $Time::HiRes::VERSION >= 1.9764
!($^O =~ /win/i) $Time::HiRes::VERSION >= 1.9764
Truth table33%1/3
not(A) || B
A= !($^O =~ /win/i)B= $Time::HiRes::VERSION >= 1.9764
ABresult
1X1
011
000
18 21 our $QUIET = 0;
19  
20 =head1 NAME
21  
22 Benchmark::MCE - Perl multi-core benchmarking framework
23  
24 =head1 SYNOPSIS
25  
26 use Benchmark::MCE;
27  
28 # Run 2 benchmarks (custom functions) and time them on a single core:
29 my %stat_single = suite_run({
30 threads => 1,
31 bench => {
32 Bench1 => sub { ...code1... },
33 Bench2 => '...code2...' # String is also fine
34 }
35 );
36  
37 # Run each across multiple cores.
38 # Use the extended (arrayref) definition to check for correctness of output.
39 my %stat_multi = suite_run({
40 threads => system_identity(1), # Workers count equal to system logical cores
41 bench => {
42 Bench1 => [\&code1, $expected_output1],
43 Bench2 => [\&code2, $expected_output2],
44 }
45 );
46
47 # Calculate the multi/single core scalability
48 my %scal = calc_scalability(\%stat_single, \%stat_multi);
49  
50 =head1 DESCRIPTION
51  
52 A benchmarking framework originally designed for the L<Benchmark::DKbench> multi-core
53 CPU benchmarking suite. Released as a stand-alone to be used for custom benchmarks
54 of any type, as well as other kinds of stress-testing, throughput testing etc.
55  
56 You define custom functions (usually with randomized workloads) that can be run on
57 any number of parallel workers, using the low-overhead Many-Core Engine (L<MCE>).
58  
59 =head1 FUNCTIONS
60
61 =head2 C<system_identity>
62  
63 my $cores = system_identity($quiet?);
64  
65 Prints out software/hardware configuration and returns the number of logical cores
66 detected using L<System::CPU>.
67  
68 Any argument will suppress printout and will only return the number of cores.
69  
70 =head2 C<suite_run>
71  
72 my %stats = suite_run(\%options);
73  
74 Runs the benchmark suite given the C<%options> and prints results. Returns a hash
75 with run stats that looks like this:
76  
77 %stats = (
78 $bench_name_1 => {times => [ ... ], scores => [ ... ]},
79 ...
80 _total => {times => [ ... ], scores => [ ... ]},
81 _opt => {iter => $iterations, threads => $no_threads, ...}
82 );
83  
84 Note that the times reported will be average times per thread (or per function
85 call if you prefer), however the scores reported (if a reference time is supplied)
86 are sums across all threads. So you expect for ideal scaling 1 thread vs 2 threads
87 to return the same times, double the scores.
88  
89 =head3 Options:
90  
91 =over 4
92  
93 =item * C<bench> (HashRef, with alias C<benchmarks>) B<required>:
94 A hashref with keys being your unique custom benchmark names and values being
95 arrays:
96  
97 C<< name => [ $coderef, $expected?, $ref_time?, $quick_arg?, $normal_arg? ] >>
98  
99 where:
100  
101 =over 4
102  
103 =item * C<$coderef> B<required>:
104 Reference to your benchmark function. See L<BENCHMARK FUNCTIONS> for more details.
105  
106 =item * C<$expected>:
107 Expected output of the benchmark function on successful run (for PASS/FAIL - PASS
108 will be always assumed is parameter is undefined).
109  
110 =item * C<$ref_time>:
111 Reference time in seconds for score of 1000.
112  
113 =item * C<$quick_arg>:
114 Argument to pass to the benchmark function in C<quick> mode (for workload scaling).
115  
116 =item * C<$normal_arg>:
117 Argument to pass to the benchmark function in normal mode (for workload scaling).
118  
119 =back
120  
121 =item * C<threads> (Int; default 1):
122 Parallel benchmark threads. They are L<MCE> workers, so not 'threads' in the technical
123 sense. Each of the benchmarks defined will launch on each of the threads, hence the
124 total workload is multiplied by the number of C<threads>. Times will be averaged
125 across threads, while scores will be summed.
126  
127 =item * C<iter> (Int; default 1):
128 Number of suite iterations (with min/max/avg at the end when > 1).
129  
130 =item * C<include> (Regex):
131 Only run benchmarks whose names match regex.
132  
133 =item * C<exclude> (Regex):
134 Skip benchmarks whose names match regex.
135  
136 =item * C<filter> (CodeRef):
137 Custom filter callback for finer control. It receives C<($opt, $bench, $bench_def)>
138 and should return true to run a benchmark.
139  
140 =item * C<time> (Bool):
141 Report time (sec) instead of score. Set to true by C<quick> or if at least one
142 benchmark has no reference time declared. Otherwise score output is the default.
143  
144 =item * C<quick> (Bool; default 0):
145 Use each benchmark's quick argument and imply C<time=1>.
146  
147 =item * C<scale> (Int; default 1):
148 Scale the bench workload (number of calls of the benchmark functions) by x times.
149 Forced to 1 with C<quick> or C<no_mce>.
150  
151 =item * C<stdev> (Bool; default 0):
152 Show relative standard deviation (for C<iter> > 1).
153  
154 =item * C<sleep> (Int; default 0):
155 Number of seconds to sleep after each benchmark run.
156  
157 =item * C<duration> (Int, seconds):
158 Minimum duration in seconds for suite run (overrides C<iter>).
159  
160 =item * C<srand> (Int; default 1):
161 Define a fixed seed to keep runs reproducible when your benchmark functions use
162 C<rand>. The seed will be passed to C<srand> before each call to a benchmark
163 function. Set to 0 to skip rand seeding.
164  
165 =item * C<no_check> (Bool; default 0):
166 Do not check for Pass/Fail even if reference output is defined.
167  
168 =item * C<no_mce> (Bool; default 0):
169 Do not run under L<MCE::Loop> (sets C<threads=1>, C<scale=1>).
170  
171 =back
172  
173 =head2 C<calc_scalability>
174  
175 my %scal = calc_scalability(\%stat_single, \%stat_multi, $keep_outliers?);
176  
177 Given the C<%stat_single> results of a single-threaded C<suite_run> and C<%stat_multi>
178 results of a multi-threaded run, will calculate, print and return the multi-thread
179 scalability (including averages, ranges etc for multiple iterations).
180  
181 Unless C<$keep_outliers> is true, the overall scalability is an average after droping
182 Benchmarks that are non-scaling outliers (over 2*stdev less than the mean).
183  
184 The result hash return looks like this:
185  
186 %scal = (
187 bench_name => $bench_avg_scalability,
188 ...
189 _total => $total_avg_scalability
190 );
191  
192  
193 =head2 C<suite_calc>
194  
195 my ($stats, $stats_multi, $scal) = suite_calc(\%suite_run_options, $keep_outliers?);
196  
197 Convenience function that combines 3 calls, L</suite_run> with C<threads=E<gt>1>,
198 L</suite_run> with C<threads=E<gt>system_identity(1)> and L</calc_scalability> with
199 the results of those two, returning hashrefs with the results of all three calls.
200  
201 For single-core systems (or when C<system_identity(1)> does not return E<gt> 1)
202 only C<$stats> will be returned.
203  
204 You can override the C<system_identity(1)> call and run the multi-thread bench with
205 a custom number of threads by passing C<threads =E<gt> [count]>.
206  
207 =head1 BENCHMARK FUNCTIONS
208  
209 The benchmark functions will be called with two parameters that you can choose to
210 take advantage of.
211 The first one is what you define as either the C<$quick_arg> or C<$normal_arg>,
212 with the intention being to have a way to run a C<quick> mode that lets you test with
213 smaller workloads. The second argument will be an integer that's the chunk number
214 from L<MCE::Loop> - it will be 1 for the call on the first thread, 2 from the second
215 thread etc, so your function may track which worker/chunk is running.
216  
217 The function may return a string, usually a checksum, that will be checked against
218 the (optional) C<$expected> parameter to show a Pass/Fail (useful for verifying
219 correctness, stress testing, etc.).
220  
221 Example:
222  
223 use Benchmark::MCE;
224 use Math::Trig qw/:great_circle :pi/;
225  
226 sub great_circle {
227 my $size = shift || 1; # Optionally have an argument that scales the workload
228 my $chunk = shift; # Optionally use the chunk number
229 my $dist = 0;
230 $dist +=
231 great_circle_distance(rand(pi), rand(2 * pi), rand(pi), rand(2 * pi))
232 for 1 .. $size;
233 return $dist; # Returning a value is optional for the Pass/Fail functionality
234 }
235  
236 my %stats = suite_run({
237 bench => { 'Math::Trig' => # A unique name for the benchmark
238 [
239 \&great_circle, # Reference to bench function
240 '3144042.81433949', # Reference output - determines Pass/Fail (optional)
241 5.5, # Seconds to complete in normal mode for score = 1000 (optional)
242 1000000, # Argument to pass for quick mode (optional)
243 5000000 # Argument to pass for normal mode (optional)
244 ]},
245 }
246 );
247  
248 =head1 STDOUT / QUIET MODE
249  
250 Normally function calls will print results to C<STDOUT> as well as return them.
251 You can suppress STDOUT by setting:
252  
253 $Benchmark::MCE::QUIET = 1;
254  
255 =head1 NOTES
256  
257 The framework uses a monotonic timer for non-Windows systems with at least v1.9764
258 of C<Time::HiRes> (C<$Benchmark::MCE::MONO_CLOCK> will be true).
259  
260 =head1 AUTHOR
261  
262 Dimitrios Kechagias, C<< <dkechag at cpan.org> >>
263  
264 =head1 BUGS
265  
266 Please report any bugs or feature requests on L<GitHub|https://github.com/SpareRoom/Benchmark-MCE>.
267  
268 =head1 GIT
269  
270 L<https://github.com/SpareRoom/Benchmark-MCE>
271  
272 =head1 LICENSE AND COPYRIGHT
273  
274 Copyright (c) 2025-2026 Dimitrios Kechagias and SpareRoom.
275  
276 This is free software; you can redistribute it and/or modify it under
277 the same terms as the Perl 5 programming language system itself.
278  
279 =cut
280  
281 39 ▶sub system_identity {
Subroutine system_identity: called CC=17 SCAR=32.6
Pod documented
282 39 my ($physical, $cores, $ncpu) = System::CPU::get_cpu;
283 39 ▶ $ncpu ||= 1;
Condition100%2/2
$ncpu ||= 1
l!l
237
MC/DC100%1/1
$ncpu ||= 1
$ncpu
Truth table100%2/2
A
A= $ncpu
Aresult
11
00
284 39 ▶ return $ncpu if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 37 2 39
285  
286 2 ▶ local $^O = 'linux' if $^O =~ /android/;
Branch: 1 branch
BranchTrueFalseTotal
if $^O =~ /android/ 0 2 2
287 2 my $info = System::Info->sysinfo_hash;
288 2 ▶ my $osn = $info->{distro} || $info->{os} || $^O;
Condition33%2/6
$info->{'distro'} || $info->{'os'} || $^O
l!l&&r!l&&!r
200
$info->{"distro"} or $info->{"os"}
l!l&&r!l&&!r
200
MC/DC0%0/3
$info->{'distro'} || $info->{'os'} || $^O
$info->{"distro"} $info->{"os"} $^O
Truth table25%1/4
A or B || C
A= $info->{"distro"}B= $info->{"os"}C= $^O
ABCresult
1XX1
01X1
0011
0000
289 2 ▶ my $model = System::CPU::get_name || '';
Condition50%1/2
System::CPU::get_name() || ''
l!l
20
MC/DC0%0/1
System::CPU::get_name() || ''
System::CPU::get_name()
Truth table50%1/2
A
A= System::CPU::get_name()
Aresult
11
00
290 2 ▶ my $arch = System::CPU::get_arch || '';
Condition50%1/2
System::CPU::get_arch() || ''
l!l
20
MC/DC0%0/1
System::CPU::get_arch() || ''
System::CPU::get_arch()
Truth table50%1/2
A
A= System::CPU::get_arch()
Aresult
11
00
291 2 ▶ $arch = " ($arch)" if $arch;
Branch: 1 branch
BranchTrueFalseTotal
if $arch 2 0 2
292 2 _print("--------------- Software ---------------\n",_package_ver(),"\n");
293 _printf(
294 "Perl $^V (%sthreads, %smulti)\n",
295 $Config{usethreads} ? '' : 'no ',
296 2 ▶ $Config{usemultiplicity} ? '' : 'no '
Branch: 2 branches
BranchTrueFalseTotal
$Benchmark::MCE::Config{'usethreads'} ? : 0 2 2
$Benchmark::MCE::Config{'usemultiplicity'} ? : 0 2 2
297 );
298 2 _print("OS: $osn\n--------------- Hardware ---------------\n");
299 2 _print("CPU type: $model$arch\n");
300 2 _print("CPUs: $ncpu");
301 2 my @extra;
302 2 ▶ push @extra, "$physical Processors" if $physical && $physical > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $physical and $physical > 1 2 0 2
Condition33%1/3
$physical and $physical > 1
!ll&&!rl&&r
002
MC/DC0%0/2
$physical and $physical > 1
$physical $physical > 1
Truth table33%1/3
A and B
A= $physicalB= $physical > 1
ABresult
0X0
100
111
303 2 ▶ push @extra, "$cores Cores" if $cores;
Branch: 1 branch
BranchTrueFalseTotal
if $cores 2 0 2
304 2 ▶ push @extra, "$ncpu Threads" if $cores && $cores != $ncpu;
Branch: 1 branch
BranchTrueFalseTotal
if $cores and $cores != $ncpu 0 2 2
Condition33%1/3
$cores and $cores != $ncpu
!ll&&!rl&&r
020
MC/DC0%0/2
$cores and $cores != $ncpu
$cores $cores != $ncpu
Truth table33%1/3
A and B
A= $coresB= $cores != $ncpu
ABresult
0X0
100
111
305 2 ▶ _print(" (".join(', ', @extra).")") if @extra;
Branch: 1 branch
BranchTrueFalseTotal
if @extra 2 0 2
306 2 _print("\n".("-"x40)."\n");
307  
308 2 return $ncpu;
309 };
310  
311 64 ▶sub suite_calc {
Subroutine suite_calc: called CC=3 SCAR=11.0
Pod documented
312 64 my $opt = shift;
313 64 my $outliers = shift;
314 64 my %single = suite_run({%$opt, threads => 1});
315 59 ▶ my $cpus = $opt->{threads} || system_identity(1);
Condition66%2/3
$opt->{'threads'} || system_identity(1)
l!l&&r!l&&!r
14450
MC/DC0%0/2
$opt->{'threads'} || system_identity(1)
$opt->{'threads'} system_identity(1)
Truth table66%2/3
A || B
A= $opt->{'threads'}B= system_identity(1)
ABresult
1X1
011
000
316 59 ▶ return \%single unless $cpus > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $cpus > 1 18 41 59
317 41 my %multi = suite_run({%$opt, threads => $cpus});
318 33 return \%single, \%multi, {calc_scalability(\%single, \%multi, $outliers)};
319 }
320  
321 218 ▶sub suite_run {
Subroutine suite_run: called CC=10 SCAR=23.0
Pod documented
322 218 my $opt = shift;
323 218 _init_options($opt);
324  
325 142 my %stats;
326 142 $stats{_opt}->{$_} = $opt->{$_} foreach qw/threads scale iter time no_check/;
327  
328 142 ▶ my $thread = $opt->{threads} > 1 ? "$opt->{threads}-thread" : "single-thread";
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'threads'} > 1 ? : 42 100 142
329 142 _print(__PACKAGE__, " $thread run");
330 142 ▶ _print($opt->{no_mce} ? " (no MCE):\n" : ":\n");
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'no_mce'} ? : 4 138 142
331  
332 MCE::Loop::init {
333 max_workers => $opt->{threads},
334 chunk_size => 1,
335 142 ▶ } unless $opt->{no_mce};
Branch: 1 branch
BranchTrueFalseTotal
unless $opt->{"no_mce"} 138 4 142
336  
337 142 ▶ if ($opt->{duration}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{'duration'}) { } 1 141 142
338 1 my $t0 = _get_time();
339 1 my $cnt = 0;
340 1 my $t = 0;
341 1 ▶ while ($t < $opt->{duration}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t < $opt->{"duration"}) 1 1 2
342 1 $cnt++;
343 1 _print("Iteration $cnt (".int($t+0.5)."s of $opt->{duration}s)...\n");
344 1 _run_iteration($opt, \%stats);
345 1 $t = _get_time()-$t0;
346 }
347 1 $opt->{iter} = $cnt;
348 1 $stats{_opt}->{iter} = $cnt;
349 1 $opt->{duration} = 0;
350 } else {
351 141 foreach (1..$opt->{iter}) {
352 144 ▶ _print("Iteration $_ of $opt->{iter}...\n") if $opt->{iter} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"iter"} > 1 6 138 144
353 144 _run_iteration($opt, \%stats);
354 }
355 }
356  
357 99 ▶ _total_stats($opt, \%stats) if $opt->{iter} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"iter"} > 1 3 96 99
358  
359 99 return %stats;
360 }
361  
362 170 ▶sub calc_scalability {
Subroutine calc_scalability: called CC=27 SCAR=33.0
Pod documented
363 170 my $stats1 = shift;
364 170 my $stats2 = shift;
365 170 my $outliers = shift;
366 170 my $opt = $stats1->{_opt};
367 170 my $opt2 = $stats2->{_opt};
368  
369 die "Different, non-zero thread count expected between runs"
370 if !$opt->{threads}
371 || !$opt2->{threads}
372 170 ▶ || $opt->{threads} == $opt2->{threads};
Branch: 1 branch
BranchTrueFalseTotal
if not $opt->{"threads"} && $opt2->{"threads"} or $opt->{"threads"} == $opt2->{"threads"} 57 113 170
Condition100%6/6
not $opt->{"threads"} && $opt2->{"threads"} or $opt->{"threads"} == $opt2->{"threads"}
l!l&&r!l&&!r
3819113
$opt->{'threads'} && $opt2->{'threads'}
!ll&&!rl&&r
1919132
MC/DC100%3/3
not $opt->{"threads"} && $opt2->{"threads"} or $opt->{"threads"} == $opt2->{"threads"}
$opt->{'threads'} $opt2->{'threads'} $opt->{"threads"} == $opt2->{"threads"}
Truth table100%4/4
not(A && B) or C
A= $opt->{'threads'}B= $opt2->{'threads'}C= $opt->{"threads"} == $opt2->{"threads"}
ABCresult
0XX1
10X1
1111
1100
373  
374 ($opt, $opt2) = ($stats2->{_opt}, $stats1->{_opt})
375 113 ▶ if $opt->{threads} > $opt2->{threads};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"threads"} > $opt2->{"threads"} 20 93 113
376  
377 113 ▶ die "Same scale expected between runs" if $opt->{scale} != $opt2->{scale};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"scale"} != $opt2->{"scale"} 19 94 113
378  
379 94 my $threads = $opt2->{threads} / $opt->{threads};
380 94 ▶ my $display = $opt->{time} ? 'times' : 'scores';
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'time'} ? : 54 40 94
381  
382 94 ▶ $opt->{f} = $opt->{time} ? '%.3f' : '%5.0f';
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'time'} ? : 54 40 94
383 94 my ($cnt, @perf, @scal, %scal);
384 94 _print( "Multi thread Scalability:\n"
385 . _pad("Benchmark", 24)
386 . _pad("Multi perf xSingle", 24)
387 . _pad("Multi scalability %", 24)
388 . "\n");
389 94 foreach my $bench (sort keys %{$stats1}) {
390 284 ▶ next if $bench eq '_total';
Branch: 1 branch
BranchTrueFalseTotal
if $bench eq "_total" 56 228 284
391 228 ▶ next unless $stats1->{$bench}->{times} && $stats2->{$bench}->{times};
Branch: 1 branch
BranchTrueFalseTotal
unless $stats1->{$bench}{"times"} and $stats2->{$bench}{"times"} 128 100 228
Condition100%3/3
$stats1->{$bench}{"times"} and $stats2->{$bench}{"times"}
!ll&&!rl&&r
10622100
MC/DC100%2/2
$stats1->{$bench}{"times"} and $stats2->{$bench}{"times"}
$stats1->{$bench}{"times"} $stats2->{$bench}{"times"}
Truth table100%3/3
A and B
A= $stats1->{$bench}{"times"}B= $stats2->{$bench}{"times"}
ABresult
0X0
100
111
392 100 $cnt++;
393 100 my @res1 = _min_max_avg($stats1->{$bench}->{times});
394 100 my @res2 = _min_max_avg($stats2->{$bench}->{times});
395 100 ▶ $scal{$bench} = $res1[2]/$res2[2]*100 if $res2[2];
Branch: 1 branch
BranchTrueFalseTotal
if $res2[2] 81 19 100
396 100 ▶ push @perf, $res1[2]/$res2[2]*$threads if $res2[2];
Branch: 1 branch
BranchTrueFalseTotal
if $res2[2] 81 19 100
397 100 ▶ push @scal, $scal{$bench} if $scal{$bench};
Branch: 1 branch
BranchTrueFalseTotal
if $scal{$bench} 81 19 100
398 100 ▶ _print( _pad("$bench:", 24)
Branch: 1 branch
BranchTrueFalseTotal
if @perf 81 19 100
399 . _pad(sprintf("%.2f", $perf[-1]), 24)
400 . _pad(sprintf("%2.0f", $scal[-1]), 24) . "\n")
401 if @perf;
402 }
403 94 ▶ die "No bench times recorded" unless @perf;
Branch: 1 branch
BranchTrueFalseTotal
unless @perf 38 56 94
404 56 _print(("-"x40)."\n");
405 56 my @avg1 = _min_max_avg($stats1->{_total}->{$display});
406 56 my @avg2 = _min_max_avg($stats2->{_total}->{$display});
407 56 _print(__PACKAGE__, " summary ($cnt benchmark");
408 56 ▶ _print("s") if $cnt > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $cnt > 1 25 31 56
409 56 ▶ _print(" x$opt->{scale} scale") if $opt->{scale} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"scale"} > 1 1 55 56
410 56 ▶ _print(", $opt->{iter} iterations") if $opt->{iter} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"iter"} > 1 2 54 56
411 56 _print(", $opt2->{threads} threads):\n");
412 56 ▶ $opt->{f} .= "s" if $opt->{time};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"time"} 54 2 56
413 56 ▶ my $f = $opt->{time} ? '%.3f' : '%.0f';
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'time'} ? : 54 2 56
414 56 ▶ $f = $opt->{iter} > 1 ? "$opt->{f}\t($f - $f)" : $opt->{f};
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'iter'} > 1 ? : 2 54 56
415 56 ▶ @avg1 = $opt->{iter} > 1 ? ($avg1[2], $avg1[0], $avg1[1]) : ($avg1[2]);
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'iter'} > 1 ? : 2 54 56
416 56 ▶ @avg2 = $opt->{iter} > 1 ? ($avg2[2], $avg2[0], $avg2[1]) : ($avg2[2]);
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'iter'} > 1 ? : 2 54 56
417 56 _print(_pad("Single:").sprintf($f, @avg1)."\n");
418 56 _print(_pad("Multi:").sprintf($f, @avg2)."\n");
419 56 ▶ my @newperf = $outliers ? @perf : _drop_outliers(\@perf, -1);
Branch: 1 branch
BranchTrueFalseTotal
$outliers ? : 19 37 56
420 56 ▶ my @newscal = $outliers ? @scal : _drop_outliers(\@scal, -1);
Branch: 1 branch
BranchTrueFalseTotal
$outliers ? : 19 37 56
421 56 @perf = _min_max_avg(\@newperf);
422 56 @scal = _min_max_avg(\@newscal);
423 56 $scal{_total} = $scal[2];
424 56 _print( _pad("Multi/Single perf:")
425 . sprintf("%.2fx\t(%.2f - %.2f)", $perf[2], $perf[0], $perf[1])
426 . "\n");
427 56 _print(
428 _pad("Multi scalability:") . sprintf(
429 "%2.1f%% \t(%.0f%% - %.0f%%)", $scal[2], $scal[0], $scal[1]
430 )
431 . "\n"
432 );
433  
434 56 return %scal;
435 }
436  
437 218 ▶sub _init_options {
Subroutine _init_options: called CC=25 SCAR=32.2
438 218 my $opt = shift;
439 218 ▶ $opt->{iter} ||= $opt->{iterations} || 1;
Condition80%4/5
$opt->{"iter"} ||= $opt->{"iterations"} || 1
l!l&&r!l&&!r
981200
$opt->{'iterations'} || 1
l!l
1119
MC/DC0%0/2
$opt->{"iter"} ||= $opt->{"iterations"} || 1
$opt->{"iter"} $opt->{'iterations'}
Truth table66%2/3
A ||= B
A= $opt->{"iter"}B= $opt->{'iterations'}
ABresult
1X1
011
000
440 218 ▶ $opt->{bench} ||= $opt->{benchmarks} || $opt->{extra_bench};
Condition100%6/6
$opt->{"bench"} ||= $opt->{"benchmarks"} || $opt->{"extra_bench"}
l!l&&r!l&&!r
197219
$opt->{'benchmarks'} || $opt->{'extra_bench'}
l!l&&r!l&&!r
1119
MC/DC0%0/3
$opt->{"bench"} ||= $opt->{"benchmarks"} || $opt->{"extra_bench"}
$opt->{"bench"} $opt->{'benchmarks'} $opt->{'extra_bench'}
Truth table0%0/4
A ||= B || C
A= $opt->{"bench"}B= $opt->{'benchmarks'}C= $opt->{'extra_bench'}
ABCresult
1XX1
01X1
0011
0000
441 218 ▶ die "No benchmarks defined" unless $opt->{bench} && %{$opt->{bench}};
Branch: 1 branch
BranchTrueFalseTotal
unless $opt->{"bench"} and %{$opt->{"bench"};} 38 180 218
Condition100%3/3
$opt->{"bench"} and %{$opt->{"bench"};}
!ll&&!rl&&r
1919180
MC/DC100%2/2
$opt->{"bench"} and %{$opt->{"bench"};}
$opt->{"bench"} %{$opt->{"bench"};}
Truth table100%3/3
A and B
A= $opt->{"bench"}B= %{$opt->{"bench"};}
ABresult
0X0
100
111
442 180 foreach my $b (keys %{$opt->{bench}}) {
443 682 ▶ if (!ref($opt->{bench}->{$b})) { # string
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $opt->{"bench"}{$b}) 31 651 682
444 31 my $f = eval "sub { $opt->{bench}->{$b} }";
445 31 ▶ die "Error compiling benchmark '$b': $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 19 12 31
446 12 $opt->{bench}->{$b} = $f;
447 }
448 $opt->{bench}->{$b} = [$opt->{bench}->{$b}]
449 663 ▶ if ref($opt->{bench}->{$b}) eq 'CODE'; # wrap coderef
Branch: 1 branch
BranchTrueFalseTotal
if ref $opt->{"bench"}{$b} eq "CODE" 24 639 663
450 die "Error defining benchmark '$b'"
451 663 ▶ if ref($opt->{bench}->{$b}) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $opt->{"bench"}{$b} ne "ARRAY" 19 644 663
452 }
453 142 ▶ $opt->{threads} ||= 1;
Condition100%2/2
$opt->{"threads"} ||= 1
l!l
10834
MC/DC100%1/1
$opt->{"threads"} ||= 1
$opt->{"threads"}
Truth table100%2/2
A
A= $opt->{"threads"}
Aresult
11
00
454 142 ▶ $opt->{scale} ||= 1;
Condition100%2/2
$opt->{"scale"} ||= 1
l!l
1141
MC/DC100%1/1
$opt->{"scale"} ||= 1
$opt->{"scale"}
Truth table100%2/2
A
A= $opt->{"scale"}
Aresult
11
00
455 142 ▶ ($opt->{time}, $opt->{no_check}) = (1, 1) if $opt->{quick};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"quick"} 67 75 142
456 142 ▶ $opt->{scale} = 1 if $opt->{quick} || $opt->{no_mce};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"quick"} or $opt->{"no_mce"} 69 73 142
Condition100%3/3
$opt->{"quick"} or $opt->{"no_mce"}
l!l&&r!l&&!r
67273
MC/DC100%2/2
$opt->{"quick"} or $opt->{"no_mce"}
$opt->{"quick"} $opt->{"no_mce"}
Truth table100%3/3
A or B
A= $opt->{"quick"}B= $opt->{"no_mce"}
ABresult
1X1
011
000
457 142 foreach my $arr (values %{$opt->{bench}}) {
458 644 ▶ $opt->{time} = 1 unless scalar(@$arr) > 2 && $arr->[2] && $arr->[2] > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$arr > 2 and $arr->[2] and $arr->[2] > 0 46 598 644
Condition83%5/6
scalar @$arr > 2 and $arr->[2] and $arr->[2] > 0
!ll&&!rl&&r
460598
scalar @$arr > 2 and $arr->[2]
!ll&&!rl&&r
451598
MC/DC66%2/3
scalar @$arr > 2 and $arr->[2] and $arr->[2] > 0
scalar @$arr > 2 $arr->[2] $arr->[2] > 0
Truth table75%3/4
A and B and C
A= scalar @$arr > 2B= $arr->[2]C= $arr->[2] > 0
ABCresult
0XX0
10X0
1100
1111
459 644 ▶ $opt->{no_check} = 1 unless scalar(@$arr) > 1 && defined $arr->[1];
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$arr > 1 and defined $arr->[1] 69 575 644
Condition100%3/3
scalar @$arr > 1 and defined $arr->[1]
!ll&&!rl&&r
4425575
MC/DC100%2/2
scalar @$arr > 1 and defined $arr->[1]
scalar @$arr > 1 defined $arr->[1]
Truth table100%3/3
A and B
A= scalar @$arr > 1B= defined $arr->[1]
ABresult
0X0
100
111
460 }
461 142 ▶ $opt->{f} = $opt->{time} ? '%.3f' : '%5.0f';
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'time'} ? : 91 51 142
462 142 ▶ $opt->{threads} = 1 if $opt->{no_mce};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"no_mce"} 4 138 142
463 }
464  
465 145 ▶sub _run_iteration {
Subroutine _run_iteration: called CC=19 SCAR=29.4
466 145 my $opt = shift;
467 145 my $stats = shift;
468 145 my $benchmarks = $opt->{bench};
469 145 ▶ my $title = $opt->{time} ? 'Time (sec)' : 'Score';
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'time'} ? : 93 52 145
470 145 _print(_pad("Benchmark")._pad($title));
471 145 ▶ _print("Pass/Fail") unless $opt->{no_check};
Branch: 1 branch
BranchTrueFalseTotal
unless $opt->{"no_check"} 52 93 145
472 145 _print("\n");
473 145 my ($total_score, $total_time, $i) = (0, 0, 0);
474 145 foreach my $bench (sort keys %$benchmarks) {
475 618 ▶ next if $opt->{filter} && !$opt->{filter}->($opt, $bench, $benchmarks->{$bench});
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"filter"} and not $opt->{"filter"}->($opt, $bench, $benchmarks->{$bench}) 30 588 618
Condition100%3/3
$opt->{"filter"} and not $opt->{"filter"}->($opt, $bench, $benchmarks->{$bench})
!ll&&!rl&&r
5682030
MC/DC100%2/2
$opt->{"filter"} and not $opt->{"filter"}->($opt, $bench, $benchmarks->{$bench})
$opt->{"filter"} not $opt->{"filter"}->($opt, $bench, $benchmarks->{$bench})
Truth table100%3/3
A and not(B)
A= $opt->{"filter"}B= not $opt->{"filter"}->($opt, $bench, $benchmarks->{$bench})
ABresult
0X0
100
111
476 588 ▶ next if $opt->{exclude} && $bench =~ /$opt->{exclude}/;
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"exclude"} and $bench =~ /$opt->{"exclude"}/ 21 567 588
Condition100%3/3
$opt->{"exclude"} and $bench =~ /$opt->{"exclude"}/
!ll&&!rl&&r
4838421
MC/DC100%2/2
$opt->{"exclude"} and $bench =~ /$opt->{"exclude"}/
$opt->{"exclude"} $bench =~ /$opt->{"exclude"}/
Truth table100%3/3
A and B
A= $opt->{"exclude"}B= $bench =~ /$opt->{"exclude"}/
ABresult
0X0
100
111
477 567 ▶ next if $opt->{include} && $bench !~ /$opt->{include}/;
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"include"} and not $bench =~ /$opt->{"include"}/ 403 164 567
Condition100%3/3
$opt->{"include"} and not $bench =~ /$opt->{"include"}/
!ll&&!rl&&r
7589403
MC/DC100%2/2
$opt->{"include"} and not $bench =~ /$opt->{"include"}/
$opt->{"include"} not $bench =~ /$opt->{"include"}/
Truth table100%3/3
A and not(B)
A= $opt->{"include"}B= not $bench =~ /$opt->{"include"}/
ABresult
0X0
100
111
478 164 my ($time, $res) = _mce_bench_run($opt, $benchmarks->{$bench});
479 my $score =
480 $benchmarks->{$bench}->[2] && $time
481 146 ▶ ? int(1000 * $opt->{threads} * $benchmarks->{$bench}->[2] / $time + 0.5)
Branch: 1 branch
BranchTrueFalseTotal
$benchmarks->{$bench}[2] && $time ? : 107 39 146
Condition66%2/3
$benchmarks->{$bench}[2] and $time
!ll&&!rl&&r
390107
MC/DC50%1/2
$benchmarks->{$bench}[2] and $time
$benchmarks->{$bench}[2] $time
Truth table66%2/3
A and B
A= $benchmarks->{$bench}[2]B= $time
ABresult
0X0
100
111
482 : 1;
483 146 $total_score += $score;
484 146 $total_time += $time;
485 146 $i++;
486 146 push @{$stats->{$bench}->{times}}, $time;
487 146 push @{$stats->{$bench}->{scores}}, $score;
488 146 ▶ my $d = $stats->{$bench}->{$opt->{time} ? 'times' : 'scores'}->[-1];
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'time'} ? : 111 35 146
489 146 ▶ $stats->{$bench}->{fail}++ if !$opt->{quick} && $res ne 'Pass';
Branch: 1 branch
BranchTrueFalseTotal
if not $opt->{"quick"} and $res ne "Pass" 43 103 146
Condition100%3/3
not $opt->{"quick"} and $res ne "Pass"
!ll&&!rl&&r
653843
MC/DC100%2/2
not $opt->{"quick"} and $res ne "Pass"
not $opt->{"quick"} $res ne "Pass"
Truth table100%3/3
not(A) and B
A= not $opt->{"quick"}B= $res ne "Pass"
ABresult
0X0
100
111
490 146 _print(_pad("$bench:")._pad(sprintf($opt->{f}, $d)));
491 146 ▶ _print("$res") unless $opt->{no_check};
Branch: 1 branch
BranchTrueFalseTotal
unless $opt->{"no_check"} 43 103 146
492 146 _print("\n");
493 146 ▶ sleep $opt->{sleep} if $opt->{sleep};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"sleep"} 1 145 146
494 }
495 127 ▶ die "No benchmarks to run\n" unless $i;
Branch: 1 branch
BranchTrueFalseTotal
unless $i 25 102 127
496 102 my $s = int($total_score/$i+0.5);
497 _print(_pad("Overall $title: ")
498 102 ▶ . sprintf($opt->{f} . "\n", $opt->{time} ? $total_time : $s));
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'time'} ? : 81 21 102
499 102 push @{$stats->{_total}->{times}}, $total_time;
500 102 push @{$stats->{_total}->{scores}}, $s;
501 }
502  
503 164 ▶sub _mce_bench_run {
Subroutine _mce_bench_run: called CC=6 SCAR=17.9
504 164 my $opt = shift;
505 164 my $benchmark = shift;
506 164 my @bench_copy = @$benchmark;
507 164 ▶ $bench_copy[3] = $bench_copy[4] if scalar(@bench_copy) > 3 && !$opt->{quick};
Branch: 1 branch
BranchTrueFalseTotal
if scalar @bench_copy > 3 and not $opt->{"quick"} 39 125 164
Condition100%3/3
scalar @bench_copy > 3 and not $opt->{"quick"}
!ll&&!rl&&r
616439
MC/DC100%2/2
scalar @bench_copy > 3 and not $opt->{"quick"}
scalar @bench_copy > 3 not $opt->{"quick"}
Truth table100%3/3
A and not(B)
A= scalar @bench_copy > 3B= not $opt->{"quick"}
ABresult
0X0
100
111
508 164 ▶ return _bench_run(\@bench_copy, 1, $opt->{srand}) if $opt->{no_mce};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"no_mce"} 9 155 164
509  
510 18 ▶ my @stats = mce_loop {
Subroutine __ANON__: called CC=2 SCAR=6.9
511 18 my ($mce, $chunk_ref, $chunk_id) = @_;
512 18 for (@{$chunk_ref}) {
513 18 my ($time, $res) = _bench_run(\@bench_copy, $_, $opt->{srand});
514 18 MCE->gather([$time, $res]);
515 }
516 }
517 155 (1 .. $opt->{threads} * $opt->{scale});
518  
519 137 my ($res, $time) = ('Pass', 0);
520 137 foreach (@stats) {
521 179 $time += $_->[0];
522 179 ▶ $res = $_->[1] if $_->[1] ne 'Pass';
Branch: 1 branch
BranchTrueFalseTotal
if $_->[1] ne "Pass" 128 51 179
523 }
524  
525 137 return $time/$opt->{threads} * $opt->{scale}, $res;
526 }
527  
528 46 ▶sub _bench_run {
Subroutine _bench_run: called CC=5 SCAR=16.1
529 46 my $benchmark = shift;
530 46 my $chunk_no = shift;
531 46 ▶ my $srand = shift // 1;
Condition100%2/2
shift() // 1
l!l
541
MC/DC100%1/1
shift() // 1
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
532 46 ▶ srand($srand) if $srand > 0; # For repeatability
Branch: 1 branch
BranchTrueFalseTotal
if $srand > 0 41 5 46
533 46 my $t0 = _get_time();
534 46 my $out = $benchmark->[0]->($benchmark->[3], $chunk_no);
535 27 my $time = sprintf("%.3f", _get_time()-$t0);
536 27 ▶ my $r = !defined $benchmark->[1]
Branch: 1 branch
BranchTrueFalseTotal
!defined($benchmark->[1]) || $out eq $benchmark->[1] ? : 15 12 27
Condition66%2/3
not defined $benchmark->[1] or $out eq $benchmark->[1]
l!l&&r!l&&!r
15012
MC/DC50%1/2
not defined $benchmark->[1] or $out eq $benchmark->[1]
not defined $benchmark->[1] $out eq $benchmark->[1]
Truth table66%2/3
not(A) or B
A= not defined $benchmark->[1]B= $out eq $benchmark->[1]
ABresult
1X1
011
000
537 || $out eq $benchmark->[1] ? 'Pass' : "Fail ($out)";
538 27 return $time, $r;
539 }
540  
541 3 ▶sub _total_stats {
Subroutine _total_stats: called CC=10 SCAR=23.0
542 3 my $opt = shift;
543 3 my $stats = shift;
544 3 ▶ my $display = $opt->{time} ? 'times' : 'scores';
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'time'} ? : 2 1 3
545 3 ▶ my $title = $opt->{time} ? 'Time (sec)' : 'Score';
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'time'} ? : 2 1 3
546 _print( "Aggregates ($opt->{iter} iterations"
547 3 ▶ . ($opt->{threads} > 1 ? ", $opt->{threads} threads" : "") . "):\n"
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'threads'} > 1 ? : 0 3 3
548 . _pad("Benchmark", 24)
549 . _pad("Avg $title")
550 . _pad("Min $title")
551 . _pad("Max $title"));
552 3 ▶ _print(_pad("stdev %")) if $opt->{stdev};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"stdev"} 1 2 3
553 3 ▶ _print(_pad("Pass %")) unless $opt->{no_check};
Branch: 1 branch
BranchTrueFalseTotal
unless $opt->{"no_check"} 1 2 3
554 3 _print("\n");
555  
556 3 foreach my $bench (sort keys %{$opt->{bench}}) {
557 15 ▶ next unless $stats->{$bench}->{$display};
Branch: 1 branch
BranchTrueFalseTotal
unless $stats->{$bench}{$display} 8 7 15
558 7 my $str = _calc_stats($opt, $stats->{$bench}->{$display});
559 7 _print(_pad("$bench:",24).$str);
560 _print(
561 _pad(
562 sprintf("%d",
563 100 * ($opt->{iter} - ($stats->{$bench}->{fail} || 0)) /
564 $opt->{iter})
565 )
566 7 ▶ ) unless $opt->{no_check};
Branch: 1 branch
BranchTrueFalseTotal
unless $opt->{"no_check"} 5 2 7
Condition50%1/2
$stats->{$bench}{'fail'} || 0
l!l
50
MC/DC0%0/1
$stats->{$bench}{'fail'} || 0
$stats->{$bench}{'fail'}
Truth table50%1/2
A
A= $stats->{$bench}{'fail'}
Aresult
11
00
567 7 _print("\n");
568 }
569  
570 3 my $str = _calc_stats($opt, $stats->{_total}->{$display});
571 3 _print(_pad("Overall Avg $title:", 24)."$str\n");
572 }
573  
574 10 ▶sub _calc_stats {
Subroutine _calc_stats: called CC=3 SCAR=11.0
575 10 my $opt = shift;
576 10 my $arr = shift;
577 10 my $pad = shift;
578 10 my ($min, $max, $avg) = _min_max_avg($arr);
579 10 my $str = join '', map {_pad(sprintf($opt->{f}, $_), $pad)} ($avg,$min,$max);
580 10 ▶ if ($opt->{stdev} && $avg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"stdev"} and $avg) 2 8 10
Condition66%2/3
$opt->{"stdev"} and $avg
!ll&&!rl&&r
802
MC/DC50%1/2
$opt->{"stdev"} and $avg
$opt->{"stdev"} $avg
Truth table66%2/3
A and B
A= $opt->{"stdev"}B= $avg
ABresult
0X0
100
111
581 2 my $stdev = _avg_stdev($arr);
582 2 $stdev *= 100/$avg;
583 2 $str .= _pad(sprintf("%0.2f%%", $stdev), $pad);
584 }
585 10 return $avg, $str;
586 }
587  
588 586 ▶sub _min_max_avg {
Subroutine _min_max_avg: called CC=2 SCAR=6.9
589 586 my $arr = shift;
590 586 ▶ return (0, 0, 0) unless @$arr;
Branch: 1 branch
BranchTrueFalseTotal
unless @$arr 57 529 586
591 529 return min(@$arr), max(@$arr), sum(@$arr)/scalar(@$arr);
592 }
593  
594 152 ▶sub _avg_stdev {
Subroutine _avg_stdev: called CC=3 SCAR=11.0
595 152 my $arr = shift;
596 152 ▶ return (0, 0) unless @$arr;
Branch: 1 branch
BranchTrueFalseTotal
unless @$arr 19 133 152
597 133 my $sum = sum(@$arr);
598 133 my $avg = $sum/scalar(@$arr);
599 133 my @sq;
600 133 push @sq, ($avg - $_)**2 for (@$arr);
601 133 my $dev = _min_max_avg(\@sq);
602 133 return $avg, sqrt($dev);
603 }
604  
605 # $single = single tail of dist curve outlier, 1 for over (right), -1 for under (left)
606 131 ▶sub _drop_outliers {
Subroutine _drop_outliers: called CC=5 SCAR=16.1
607 131 my $arr = shift;
608 131 my $single = shift;
609 131 my ($avg, $stdev) = _avg_stdev($arr);
610 131 my @newarr;
611 131 foreach (@$arr) {
612 827 ▶ if ($single) {
Branch: 1 branch
BranchTrueFalseTotal
if ($single) { } 580 247 827
613 580 ▶ push @newarr, $_ unless $single*($_ - $avg) > 2*$stdev;
Branch: 1 branch
BranchTrueFalseTotal
unless $single * ($_ - $avg) > 2 * $stdev 542 38 580
614 } else {
615 247 ▶ push @newarr, $_ unless abs($avg - $_) > 2*$stdev;
Branch: 1 branch
BranchTrueFalseTotal
unless abs $avg - $_ > 2 * $stdev 209 38 247
616 }
617 }
618 131 return @newarr;
619 }
620  
621 1494 ▶sub _pad {
Subroutine _pad: called CC=2 SCAR=6.9
622 1494 my $str = shift;
623 1494 ▶ my $len = shift || 20;
Condition100%2/2
shift() || 20
l!l
538956
MC/DC100%1/1
shift() || 20
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
624 1494 return $str." "x($len-length($str));
625 }
626  
627 2 ▶sub _printf {
Subroutine _printf: called CC=2 SCAR=6.9
628 2 ▶ printf @_ unless $QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $QUIET 1 1 2
629 }
630  
631 1707 ▶sub _print {
Subroutine _print: called CC=2 SCAR=6.9
632 1707 ▶ print @_ unless $QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $QUIET 1640 67 1707
633 }
634  
635 75 ▶sub _get_time {
Subroutine _get_time: called CC=2 SCAR=6.9
636 75 ▶ return $MONO_CLOCK
Branch: 1 branch
BranchTrueFalseTotal
$MONO_CLOCK ? : 65 10 75
637 ? Time::HiRes::clock_gettime(CLOCK_MONOTONIC)
638 : Time::HiRes::time();
639 }
640  
641 21 ▶sub _package_ver {
Subroutine _package_ver: called CC=5 SCAR=16.2
642 21 my $pkg = __PACKAGE__;
643 21 my $ver = $VERSION;
644  
645 21 my $caller = caller(0);
646 21 ▶ for (my $i = 0; $i < 5; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 5) 29 2 31
647 29 ▶ my $caller = caller($i) or last;
Branch: 1 branch
BranchTrueFalseTotal
my $caller = caller $i or last 29 0 29
648 29 ▶ if ($caller eq 'Benchmark::DKbench') {
Branch: 1 branch
BranchTrueFalseTotal
if ($caller eq "Benchmark::DKbench") 19 10 29
649 19 $pkg = $caller;
650 19 ▶ $ver = eval {$caller->VERSION} || '';
Condition50%1/2
eval { do { $caller->VERSION } } || ''
l!l
190
MC/DC0%0/1
eval { do { $caller->VERSION } } || ''
eval { do { $caller->VERSION } }
Truth table50%1/2
A
A= eval { do { $caller->VERSION } }
Aresult
11
00
651 19 last;
652 }
653 }
654  
655 21 return "$pkg v$ver";
656 }
657  
658 21 1;
↑ Summary