@@ -40,7 +40,7 @@ our @EXPORT = qw(system_identity suite_run calc_scalability);
40
40
our $datadir = dist_dir(" Benchmark-DKbench" );
41
41
my $mono_clock = $^O !~ / win/i || $Time::HiRes::VERSION >= 1.9764;
42
42
43
- our $VERSION = ' 2.4 ' ;
43
+ our $VERSION = ' 2.5 ' ;
44
44
45
45
=head1 NAME
46
46
@@ -68,7 +68,7 @@ performance of systems when running computationally intensive Perl (both pure Pe
68
68
and C/XS) workloads. It is a good overall indicator for generic CPU performance in
69
69
real-world scenarios. It runs single and multi-threaded (able to scale to hundreds
70
70
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 .
72
72
73
73
=head1 INSTALLATION
74
74
@@ -316,8 +316,20 @@ Prints out software/hardware configuration and returns then number of cores dete
316
316
Runs the benchmark suite given the C<%options > and prints results. Returns a hash
317
317
with run stats.
318
318
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.
321
333
322
334
=head2 C<calc_scalability >
323
335
@@ -326,6 +338,44 @@ except C<help>, C<setup> and C<max_threads> which are command-line only.
326
338
Given the C<%stat_single > results of a single-threaded C<suite_run > and C<%stat_multi >
327
339
results of a multi-threaded run, will calculate and print the multi-thread scalability.
328
340
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
+
329
379
=head1 NOTES
330
380
331
381
The benchmark suite was created to compare the performance of various cloud offerings.
@@ -373,17 +423,18 @@ L<https://github.com/dkechag/Benchmark-DKbench>
373
423
374
424
=head1 LICENSE AND COPYRIGHT
375
425
376
- This software is copyright (c) 2021-2023 by Dimitrios Kechagias.
426
+ This software is copyright (c) 2021-2024 by Dimitrios Kechagias.
377
427
378
428
This is free software; you can redistribute it and/or modify it under
379
429
the same terms as the Perl 5 programming language system itself.
380
430
381
431
=cut
382
432
383
433
sub benchmark_list {
434
+ my $extra_bench = shift || {};
384
435
return { # idx : 0 = result, 1 = ref time, 2 = func, 3 = quick test, 4 = normal test, 5 = ver
385
436
' 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],
387
438
' BioPerl Monomers' => [' d29ed0a5c205c803c112be1338d1f060' , 5.241, \&bench_bioperl_mono, 6, 20],
388
439
' Crypt::JWT' => [' d41d8cd98f00b204e9800998ecf8427e' , 6.451, \&bench_jwt, 250, 900],
389
440
' CSS::Inliner' => [' 82c1b6de9ca0500a48f8a8df0998df3c' , 4.603, \&bench_css, 2, 5],
@@ -403,6 +454,7 @@ sub benchmark_list {
403
454
' Regex/Subst utf8' => [' 857eb4e63a4d174ca4a16fe678f7626f' , 5.703, \&bench_regex_utf8, 3, 10],
404
455
' Text::Levenshtein' => [' 2948a300ed9131fa0ce82bb5eabb8ded' , 5.539, \&bench_textlevenshtein, 7, 25, 2.1],
405
456
' Time::Piece' => [' 2d4b149fe7f873a27109fc376d69211b' , 5.907, \&bench_timepiece, 75_000, 275_000],
457
+ %$extra_bench
406
458
};
407
459
}
408
460
@@ -437,6 +489,7 @@ sub suite_run {
437
489
$datadir = $opt -> {datapath } if $opt -> {datapath };
438
490
$opt -> {threads } //= 1;
439
491
$opt -> {scale } //= 1;
492
+ $opt -> {iter } ||= 1;
440
493
$opt -> {f } = $opt -> {time } ? ' %.3f' : ' %5.0f' ;
441
494
my %stats = (threads => $opt -> {threads });
442
495
@@ -457,9 +510,9 @@ sub suite_run {
457
510
458
511
sub calc_scalability {
459
512
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' ;
463
516
$opt -> {f } = $opt -> {time } ? ' %.3f' : ' %5.0f' ;
464
517
my (@perf , @scal );
465
518
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 {
497
550
498
551
sub run_iteration {
499
552
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' ;
502
555
print pad_to(" Benchmark" ).pad_to($title );
503
556
print " Pass/Fail" unless $opt -> {time };
504
557
print " \n " ;
@@ -584,7 +637,7 @@ sub bench_astro {
584
637
585
638
sub bench_bioperl_codons {
586
639
my $skip = shift ;
587
- my $iter = shift ;
640
+ my $iter = shift || 1 ;
588
641
my $d = Digest-> new(" MD5" );
589
642
my $file = catfile($datadir , " gbbct5.seq" );
590
643
foreach (1..$iter ) {
@@ -1049,9 +1102,9 @@ sub bench_timepiece {
1049
1102
1050
1103
sub total_stats {
1051
1104
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' ;
1055
1108
print " Aggregates ($opt ->{iter} iterations):\n " .pad_to(" Benchmark" ,24).pad_to(" Avg $title " ).pad_to(" Min $title " ).pad_to(" Max $title " );
1056
1109
print pad_to(" stdev %" ) if $opt -> {stdev };
1057
1110
print pad_to(" Pass %" ) unless $opt -> {time };
0 commit comments