Skip to content

Commit 1542f22

Browse files
committed
v2.5 - Custom benchmarks
1 parent cd0727b commit 1542f22

File tree

7 files changed

+132
-25
lines changed

7 files changed

+132
-25
lines changed

Changes

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

3+
2.4 2024-04-24
4+
- Added support for custom benchmarks.
5+
- Corrected BioPerl Codons bench.
6+
- Updated some reference modules.
7+
38
2.4 2023-09-29
49
- Added --scale and --stdev options.
510

MANIFEST

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ README
7373
setup_dkbench
7474
t/00-load.t
7575
t/cover.t
76+
t/custom.t
7677
t/simple.t
7778
xt/author/manifest.t
7879
xt/author/pod.t

README.md

+54-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ performance of systems when running computationally intensive Perl (both pure Pe
2424
and C/XS) workloads. It is a good overall indicator for generic CPU performance in
2525
real-world scenarios. It runs single and multi-threaded (able to scale to hundreds
2626
of CPUs) and can be fully customized to run the benchmarks that better suit your own
27-
scenario.
27+
scenario - even allowing you to add your own custom benchmarks.
2828

2929
# INSTALLATION
3030

@@ -248,8 +248,20 @@ Prints out software/hardware configuration and returns then number of cores dete
248248
Runs the benchmark suite given the `%options` and prints results. Returns a hash
249249
with run stats.
250250

251-
The options accepted are the same as the `dkbench` script (in their long form),
252-
except `help`, `setup` and `max_threads` which are command-line only.
251+
The options of the `dkbench` script (in their long form) are accepted, except
252+
`help`, `setup` and `max_threads` which are exclusive to the command-line script.
253+
254+
In addition, `%options` may contain the key `%extra_bench`, with a hashref value
255+
containing custom benchmarks in the following format:
256+
257+
extra_bench => { bench_name => [$exp_output, $ref_time, $coderef, $quick_arg, $normal_arg] ... }
258+
259+
Where `bench_name` is a unique name for each benchmark and the arrayref assigned
260+
to it contains: The expected output (string) for the test to be considered a pass,
261+
the reference time in seconds for a score of 1000, a reference to the actual bench
262+
function, an argument (workload scaling) to pass to the function for the `quick`
263+
bench run and an argument to pass for the normal run. For more info with an example
264+
see the ["CUSTOM BENCHMARKS"](#custom-benchmarks) section.
253265

254266
## `calc_scalability`
255267

@@ -258,6 +270,44 @@ except `help`, `setup` and `max_threads` which are command-line only.
258270
Given the `%stat_single` results of a single-threaded `suite_run` and `%stat_multi`
259271
results of a multi-threaded run, will calculate and print the multi-thread scalability.
260272

273+
# CUSTOM BENCHMARKS
274+
275+
Version 2.5 introduced the ability to add custom benchmarks to be run along any
276+
of the included ones of the suite. This allows you to create a suite that is more
277+
relevant to you, by including the actual code you will be running on the systems
278+
you are benchmarking. Remember, the best benchmark is your own code.
279+
280+
Here is an example of adding a benchmark to the test suite and running it together
281+
with the default benchmarks:
282+
283+
use Benchmark::DKbench;
284+
use Math::Trig qw/:great_circle :pi/;
285+
286+
sub great_circle {
287+
my $iter = shift || 1; # Optionally have an argument that scales the workload
288+
my $dist = 0;
289+
$dist +=
290+
great_circle_distance(rand(pi), rand(2 * pi), rand(pi), rand(2 * pi)) -
291+
great_circle_bearing(rand(pi), rand(2 * pi), rand(pi), rand(2 * pi)) +
292+
great_circle_direction(rand(pi), rand(2 * pi), rand(pi), rand(2 * pi))
293+
for 1 .. $iter;
294+
return $dist;
295+
}
296+
297+
my %stats = suite_run({
298+
extra_bench => { 'Math::Trig' => # A unique name for the benchmark
299+
[
300+
'3144042.81433949', # The output for your reference Perl - determines Pass/Fail
301+
5.5, # Seconds to complete in normal mode for score = 1000
302+
\&great_circle, # Reference to bench function
303+
400000, # Argument to pass for --quick mode (if needed)
304+
2000000 # Argument to pass for normal mode (if needed)
305+
]},
306+
}
307+
);
308+
309+
You can pass the `include` option to run only the custom benchmark(s).
310+
261311
# NOTES
262312

263313
The benchmark suite was created to compare the performance of various cloud offerings.
@@ -305,7 +355,7 @@ I will be notified, and then you'll automatically be notified of progress on you
305355

306356
# LICENSE AND COPYRIGHT
307357

308-
This software is copyright (c) 2021-2023 by Dimitrios Kechagias.
358+
This software is copyright (c) 2021-2024 by Dimitrios Kechagias.
309359

310360
This is free software; you can redistribute it and/or modify it under
311361
the same terms as the Perl 5 programming language system itself.

dkbench

-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ GetOptions (
8484

8585
pod2usage({ -verbose => 1, -output => \*STDOUT, -noperldoc => 1}) if $opt{help};
8686

87-
$opt{iter} ||= 1;
8887
$opt{scale} ||= 1;
8988
($opt{time}, $opt{scale}) = (1, 1) if $opt{quick};
9089

lib/Benchmark/DKbench.pm

+68-15
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ our @EXPORT = qw(system_identity suite_run calc_scalability);
4040
our $datadir = dist_dir("Benchmark-DKbench");
4141
my $mono_clock = $^O !~ /win/i || $Time::HiRes::VERSION >= 1.9764;
4242

43-
our $VERSION = '2.4';
43+
our $VERSION = '2.5';
4444

4545
=head1 NAME
4646
@@ -68,7 +68,7 @@ performance of systems when running computationally intensive Perl (both pure Pe
6868
and C/XS) workloads. It is a good overall indicator for generic CPU performance in
6969
real-world scenarios. It runs single and multi-threaded (able to scale to hundreds
7070
of CPUs) and can be fully customized to run the benchmarks that better suit your own
71-
scenario.
71+
scenario - even allowing you to add your own custom benchmarks.
7272
7373
=head1 INSTALLATION
7474
@@ -316,8 +316,20 @@ Prints out software/hardware configuration and returns then number of cores dete
316316
Runs the benchmark suite given the C<%options> and prints results. Returns a hash
317317
with run stats.
318318
319-
The options accepted are the same as the C<dkbench> script (in their long form),
320-
except C<help>, C<setup> and C<max_threads> which are command-line only.
319+
The options of the C<dkbench> script (in their long form) are accepted, except
320+
C<help>, C<setup> and C<max_threads> which are exclusive to the command-line script.
321+
322+
In addition, C<%options> may contain the key C<%extra_bench>, with a hashref value
323+
containing custom benchmarks in the following format:
324+
325+
extra_bench => { bench_name => [$exp_output, $ref_time, $coderef, $quick_arg, $normal_arg] ... }
326+
327+
Where C<bench_name> is a unique name for each benchmark and the arrayref assigned
328+
to it contains: The expected output (string) for the test to be considered a pass,
329+
the reference time in seconds for a score of 1000, a reference to the actual bench
330+
function, an argument (workload scaling) to pass to the function for the C<quick>
331+
bench run and an argument to pass for the normal run. For more info with an example
332+
see the L<CUSTOM BENCHMARKS> section.
321333
322334
=head2 C<calc_scalability>
323335
@@ -326,6 +338,44 @@ except C<help>, C<setup> and C<max_threads> which are command-line only.
326338
Given the C<%stat_single> results of a single-threaded C<suite_run> and C<%stat_multi>
327339
results of a multi-threaded run, will calculate and print the multi-thread scalability.
328340
341+
=head1 CUSTOM BENCHMARKS
342+
343+
Version 2.5 introduced the ability to add custom benchmarks to be run along any
344+
of the included ones of the suite. This allows you to create a suite that is more
345+
relevant to you, by including the actual code you will be running on the systems
346+
you are benchmarking. Remember, the best benchmark is your own code.
347+
348+
Here is an example of adding a benchmark to the test suite and running it together
349+
with the default benchmarks:
350+
351+
use Benchmark::DKbench;
352+
use Math::Trig qw/:great_circle :pi/;
353+
354+
sub great_circle {
355+
my $iter = shift || 1; # Optionally have an argument that scales the workload
356+
my $dist = 0;
357+
$dist +=
358+
great_circle_distance(rand(pi), rand(2 * pi), rand(pi), rand(2 * pi)) -
359+
great_circle_bearing(rand(pi), rand(2 * pi), rand(pi), rand(2 * pi)) +
360+
great_circle_direction(rand(pi), rand(2 * pi), rand(pi), rand(2 * pi))
361+
for 1 .. $iter;
362+
return $dist;
363+
}
364+
365+
my %stats = suite_run({
366+
extra_bench => { 'Math::Trig' => # A unique name for the benchmark
367+
[
368+
'3144042.81433949', # The output for your reference Perl - determines Pass/Fail
369+
5.5, # Seconds to complete in normal mode for score = 1000
370+
\&great_circle, # Reference to bench function
371+
400000, # Argument to pass for --quick mode (if needed)
372+
2000000 # Argument to pass for normal mode (if needed)
373+
]},
374+
}
375+
);
376+
377+
You can pass the C<include> option to run only the custom benchmark(s).
378+
329379
=head1 NOTES
330380
331381
The benchmark suite was created to compare the performance of various cloud offerings.
@@ -373,17 +423,18 @@ L<https://github.com/dkechag/Benchmark-DKbench>
373423
374424
=head1 LICENSE AND COPYRIGHT
375425
376-
This software is copyright (c) 2021-2023 by Dimitrios Kechagias.
426+
This software is copyright (c) 2021-2024 by Dimitrios Kechagias.
377427
378428
This is free software; you can redistribute it and/or modify it under
379429
the same terms as the Perl 5 programming language system itself.
380430
381431
=cut
382432

383433
sub benchmark_list {
434+
my $extra_bench = shift || {};
384435
return { # idx : 0 = result, 1 = ref time, 2 = func, 3 = quick test, 4 = normal test, 5 = ver
385436
'Astro' => ['e71c7ae08f16fe26aea7cfdb72785873', 5.674, \&bench_astro, 20000, 80000],
386-
'BioPerl Codons' => ['97c443c099886ca60e99f7ab9df689b5', 8.752, \&bench_bioperl_codons, 3, 5, 1],
437+
'BioPerl Codons' => ['97c443c099886ca60e99f7ab9df689b5', 8.752, \&bench_bioperl_codons, 3, 5],
387438
'BioPerl Monomers' => ['d29ed0a5c205c803c112be1338d1f060', 5.241, \&bench_bioperl_mono, 6, 20],
388439
'Crypt::JWT' => ['d41d8cd98f00b204e9800998ecf8427e', 6.451, \&bench_jwt, 250, 900],
389440
'CSS::Inliner' => ['82c1b6de9ca0500a48f8a8df0998df3c', 4.603, \&bench_css, 2, 5],
@@ -403,6 +454,7 @@ sub benchmark_list {
403454
'Regex/Subst utf8' => ['857eb4e63a4d174ca4a16fe678f7626f', 5.703, \&bench_regex_utf8, 3, 10],
404455
'Text::Levenshtein' => ['2948a300ed9131fa0ce82bb5eabb8ded', 5.539, \&bench_textlevenshtein, 7, 25, 2.1],
405456
'Time::Piece' => ['2d4b149fe7f873a27109fc376d69211b', 5.907, \&bench_timepiece, 75_000, 275_000],
457+
%$extra_bench
406458
};
407459
}
408460

@@ -437,6 +489,7 @@ sub suite_run {
437489
$datadir = $opt->{datapath} if $opt->{datapath};
438490
$opt->{threads} //= 1;
439491
$opt->{scale} //= 1;
492+
$opt->{iter} ||= 1;
440493
$opt->{f} = $opt->{time} ? '%.3f' : '%5.0f';
441494
my %stats = (threads => $opt->{threads});
442495

@@ -457,9 +510,9 @@ sub suite_run {
457510

458511
sub calc_scalability {
459512
my ($opt, $stats1, $stats2) = @_;
460-
my $benchmarks = benchmark_list();
461-
my $threads = $stats2->{threads}/$stats1->{threads};
462-
my $display = $opt->{time} ? 'times' : 'scores';
513+
my $benchmarks = benchmark_list($opt->{extra_bench});
514+
my $threads = $stats2->{threads} / $stats1->{threads};
515+
my $display = $opt->{time} ? 'times' : 'scores';
463516
$opt->{f} = $opt->{time} ? '%.3f' : '%5.0f';
464517
my (@perf, @scal);
465518
print "Multi thread Scalability:\n".pad_to("Benchmark",24).pad_to("Multi perf xSingle",24).pad_to("Multi scalability %",24);
@@ -497,8 +550,8 @@ sub calc_scalability {
497550

498551
sub run_iteration {
499552
my ($opt, $stats) = @_;
500-
my $benchmarks = benchmark_list();
501-
my $title = $opt->{time} ? 'Time (sec)' : 'Score';
553+
my $benchmarks = benchmark_list($opt->{extra_bench});
554+
my $title = $opt->{time} ? 'Time (sec)' : 'Score';
502555
print pad_to("Benchmark").pad_to($title);
503556
print "Pass/Fail" unless $opt->{time};
504557
print "\n";
@@ -584,7 +637,7 @@ sub bench_astro {
584637

585638
sub bench_bioperl_codons {
586639
my $skip = shift;
587-
my $iter = shift;
640+
my $iter = shift || 1;
588641
my $d = Digest->new("MD5");
589642
my $file = catfile($datadir, "gbbct5.seq");
590643
foreach (1..$iter) {
@@ -1049,9 +1102,9 @@ sub bench_timepiece {
10491102

10501103
sub total_stats {
10511104
my ($opt, $stats) = @_;
1052-
my $benchmarks = benchmark_list();
1053-
my $display = $opt->{time} ? 'times' : 'scores';
1054-
my $title = $opt->{time} ? 'Time (sec)' : 'Score';
1105+
my $benchmarks = benchmark_list($opt->{extra_bench});
1106+
my $display = $opt->{time} ? 'times' : 'scores';
1107+
my $title = $opt->{time} ? 'Time (sec)' : 'Score';
10551108
print "Aggregates ($opt->{iter} iterations):\n".pad_to("Benchmark",24).pad_to("Avg $title").pad_to("Min $title").pad_to("Max $title");
10561109
print pad_to("stdev %") if $opt->{stdev};
10571110
print pad_to("Pass %") unless $opt->{time};

lib/Benchmark/DKbench/Setup.pm

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ N/NI/NIGELM/HTML-Formatter-2.16.tar.gz
2929
K/KA/KAMELKEV/CSS-Inliner-4018.tar.gz
3030
C/CJ/CJFIELDS/BioPerl-1.7.8.tar.gz
3131
E/ET/ETHER/Moose-2.2206.tar.gz
32-
D/DR/DROLSKY/DateTime-TimeZone-2.60.tar.gz
33-
D/DR/DROLSKY/DateTime-1.59.tar.gz
32+
D/DR/DROLSKY/DateTime-TimeZone-2.62.tar.gz
33+
D/DR/DROLSKY/DateTime-1.65.tar.gz
3434
D/DK/DKECHAG/Astro-Coord-Precession-0.03.tar.gz
3535
D/DK/DKECHAG/Astro-Coord-Constellations-0.01.tar.gz
3636
D/DK/DKECHAG/Image-PHash-0.3.tar.gz
3737
D/DK/DKECHAG/Math-DCT-0.04.tar.gz
38-
D/DK/DKECHAG/SQL-Inserter-0.02.tar.gz
38+
D/DK/DKECHAG/SQL-Inserter-0.04.tar.gz
3939
M/MI/MIK/CryptX-0.078.tar.gz
4040
M/MI/MIK/Crypt-JWT-0.034.tar.gz
4141
M/ML/MLEHMANN/JSON-XS-4.03.tar.gz
4242
L/LE/LETO/Math-MatrixReal-2.13.tar.gz
4343
R/RI/RIBASUSHI/SQL-Abstract-Classic-1.91.tar.gz
44-
T/TO/TONYC/Imager-1.019.tar.gz
44+
T/TO/TONYC/Imager-1.024.tar.gz
4545
U/UG/UGEXE/Text-Levenshtein-Damerau-XS-3.2.tar.gz
4646
U/UG/UGEXE/Text-Levenshtein-XS-0.503.tar.gz
4747
);

t/simple.t

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ like($std[0], qr/CPU/, 'System identity');
99
diag $std[0];
1010

1111
my %opt = (
12-
iter => 1,
1312
skip_bio => 1,
1413
time_piece => 1,
1514
time => 1,

0 commit comments

Comments
 (0)