Skip to content

Commit 77e466e

Browse files
committed
v2.8 - Added suite_calc
1 parent b2b70f4 commit 77e466e

File tree

5 files changed

+66
-4
lines changed

5 files changed

+66
-4
lines changed

Changes

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
Revision history for Benchmark-DKbench
22

3+
2.8 2024-06-24
4+
- Added suite_calc.
5+
36
2.7 2024-04-27
47
- Improved calc_scalability, returns a hash.
58
- Improved and documented suite_run output.

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,17 @@ The result hash return looks like this:
292292
_total => $total_avg_scalability
293293
);
294294

295+
## `suite_calc`
296+
297+
my ($stats, $stats_multi, $scal) = suite_calc(\%suite_run_options);
298+
299+
Convenience function that combines 3 calls, [suite\_run](https://metacpan.org/pod/suite_run) with `threads=>1`,
300+
[suite\_run](https://metacpan.org/pod/suite_run) with `threads=>system_identity(1)` and [calc\_scalability](https://metacpan.org/pod/calc_scalability) with
301+
the results of those two, returning hashrefs with the results of all three calls.
302+
303+
For single-core systems (or when `system_identity(1)` does not return > 1)
304+
only `$stats` will be returned;
305+
295306
# CUSTOM BENCHMARKS
296307

297308
Version 2.5 introduced the ability to add custom benchmarks to be run along any
@@ -348,6 +359,14 @@ If you want to do a multi-threaded run as well and then calculate scalability:
348359

349360
my %scal = calc_scalability(\%stats, \%stats_multi);
350361

362+
Or, with a single call via the convenience function [suite\_calc](https://metacpan.org/pod/suite_calc):
363+
364+
my ($stats, $stats_multi, $scal) = suite_calc({
365+
include => 'custom',
366+
extra_bench => { custom1 => [sub {my @a=split(//, 'x'x$_) for 1..10000}] }
367+
}
368+
);
369+
351370
# NOTES
352371

353372
The benchmark suite was created to compare the performance of various cloud offerings.

lib/Benchmark/DKbench.pm

+30-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ use Text::Levenshtein::XS;
3838

3939
my $mono_clock = $^O !~ /win/i || $Time::HiRes::VERSION >= 1.9764;
4040

41-
our $VERSION = '2.7';
42-
our @EXPORT = qw(system_identity suite_run calc_scalability);
41+
our $VERSION = '2.8';
42+
our @EXPORT = qw(system_identity suite_run calc_scalability suite_calc);
4343
our $datadir = dist_dir("Benchmark-DKbench");
4444

4545
=head1 NAME
@@ -360,6 +360,17 @@ The result hash return looks like this:
360360
_total => $total_avg_scalability
361361
);
362362
363+
=head2 C<suite_calc>
364+
365+
my ($stats, $stats_multi, $scal) = suite_calc(\%suite_run_options);
366+
367+
Convenience function that combines 3 calls, L<suite_run> with C<threads=E<gt>1>,
368+
L<suite_run> with C<threads=E<gt>system_identity(1)> and L<calc_scalability> with
369+
the results of those two, returning hashrefs with the results of all three calls.
370+
371+
For single-core systems (or when C<system_identity(1)> does not return E<gt> 1)
372+
only C<$stats> will be returned;
373+
363374
=head1 CUSTOM BENCHMARKS
364375
365376
Version 2.5 introduced the ability to add custom benchmarks to be run along any
@@ -416,6 +427,14 @@ If you want to do a multi-threaded run as well and then calculate scalability:
416427
417428
my %scal = calc_scalability(\%stats, \%stats_multi);
418429
430+
Or, with a single call via the convenience function L<suite_calc>:
431+
432+
my ($stats, $stats_multi, $scal) = suite_calc({
433+
include => 'custom',
434+
extra_bench => { custom1 => [sub {my @a=split(//, 'x'x$_) for 1..10000}] }
435+
}
436+
);
437+
419438
=head1 NOTES
420439
421440
The benchmark suite was created to compare the performance of various cloud offerings.
@@ -526,6 +545,15 @@ sub system_identity {
526545
return $ncpu;
527546
};
528547

548+
sub suite_calc {
549+
my $opt = shift;
550+
my %single = suite_run({%$opt, threads => 1});
551+
my $cpus = system_identity(1);
552+
return \%single unless $cpus > 1;
553+
my %multi = suite_run({%$opt, threads => $cpus});
554+
return \%single, \%multi, {calc_scalability(\%single, \%multi)};
555+
}
556+
529557
sub suite_run {
530558
my $opt = shift;
531559
_init_options($opt);

t/cover.t

+11
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,15 @@ is(system_identity(1), 1, 'System identity');
144144

145145
is(Benchmark::DKbench::benchmark_list(), Benchmark::DKbench::benchmark_list({}), 'benchmark_list');
146146

147+
my @out = suite_calc({include => 'Astro', quick => '1'});
148+
is(scalar @out, 1, 'Single Core result only');
149+
150+
my $mock2 = Test2::Mock->new(
151+
class => 'Benchmark::DKbench',
152+
override => [ system_identity => sub {return 2} ]
153+
);
154+
155+
@out = suite_calc({include => 'Astro', quick => '1'});
156+
is(scalar @out, 3, 'Multi / Scalability results');
157+
147158
done_testing();

t/simple.t

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ diag $std[0];
2323
if ($threads && $threads > 1) {
2424
$opt{include} = 'Astro';
2525
$opt{ver} = 1;
26-
@std = capture {%stats2 = suite_run({%opt, threads=>2})};
26+
@std = capture {%stats2 = suite_run({%opt, threads => 2})};
2727
diag $std[0];
2828
} else {
29-
%stats2 = %stats1;
29+
$stats2{$_} = {%{$stats1{$_}}} for qw/Astro _opt _total/;
3030
$stats2{_opt}->{threads} = 2;
3131
}
3232

3333
@std = capture {%scal = calc_scalability(\%stats1, \%stats2)};
34+
3435
like($std[0], qr/scalability/, 'Scalability');
3536
diag $std[0];
3637

0 commit comments

Comments
 (0)