Skip to content

Commit b2b70f4

Browse files
committed
v2.7 - Improve suite_run / calc_scalability
1 parent ba2e6ac commit b2b70f4

File tree

6 files changed

+281
-80
lines changed

6 files changed

+281
-80
lines changed

Changes

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

3+
2.7 2024-04-27
4+
- Improved calc_scalability, returns a hash.
5+
- Improved and documented suite_run output.
6+
37
2.6 2024-04-25
48
- Custom benchmark improvements.
59
- Fix BSD tar xattr.

README.md

+42-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# NAME
22

3-
Benchmark::DKbench - Perl CPU Benchmark
3+
Benchmark::DKbench - Perl CPU Benchmark Suite
44

55
# SYNOPSIS
66

@@ -237,21 +237,31 @@ exported functions that the `dkbench` script uses for reference:
237237

238238
## `system_identity`
239239

240-
my $cores = system_identity();
240+
my $cores = system_identity($quiet?);
241241

242-
Prints out software/hardware configuration and returns the number of cores detected.
242+
Prints out software/hardware configuration and returns the number of logical cores
243+
detected using [System::CPU](https://metacpan.org/pod/System%3A%3ACPU).
244+
245+
Any argument will suppress printout and will only return the number of cores.
243246

244247
## `suite_run`
245248

246249
my %stats = suite_run(\%options);
247250

248251
Runs the benchmark suite given the `%options` and prints results. Returns a hash
249-
with run stats.
252+
with run stats that looks like this:
253+
254+
%stats = (
255+
bench_name => {times => [ ... ], scores => [ ... ]},
256+
...
257+
_total => {times => [ ... ], scores => [ ... ]},
258+
_opt => {iter => $iterations, threads => $no_threads, ...}
259+
);
250260

251261
The options of the `dkbench` script (in their long form) are accepted, except
252262
`help`, `setup` and `max_threads` which are exclusive to the command-line script.
253263

254-
In addition, `%options` may contain the key `%extra_bench`, with a hashref value
264+
In addition, `%options` may contain the key `extra_bench`, with a hashref value
255265
containing custom benchmarks in the following format:
256266

257267
extra_bench => { bench_name => [$coderef, $exp_output, $ref_time, $quick_arg, $normal_arg], ... }
@@ -268,10 +278,19 @@ For more info with an example see the ["CUSTOM BENCHMARKS"](#custom-benchmarks)
268278

269279
## `calc_scalability`
270280

271-
calc_scalability(\%options, \%stat_single, \%stat_multi);
281+
my %scal = calc_scalability(\%stat_single, \%stat_multi);
272282

273283
Given the `%stat_single` results of a single-threaded `suite_run` and `%stat_multi`
274-
results of a multi-threaded run, will calculate and print the multi-thread scalability.
284+
results of a multi-threaded run, will calculate, print and return the multi-thread
285+
scalability (including averages, ranges etc for multiple iterations.
286+
287+
The result hash return looks like this:
288+
289+
%scal = (
290+
bench_name => $bench_avg_scalability,
291+
...
292+
_total => $total_avg_scalability
293+
);
275294

276295
# CUSTOM BENCHMARKS
277296

@@ -290,10 +309,8 @@ with the default benchmarks:
290309
my $iter = shift || 1; # Optionally have an argument that scales the workload
291310
my $dist = 0;
292311
$dist +=
293-
great_circle_distance(rand(pi), rand(2 * pi), rand(pi), rand(2 * pi)) -
294-
great_circle_bearing(rand(pi), rand(2 * pi), rand(pi), rand(2 * pi)) +
295-
great_circle_direction(rand(pi), rand(2 * pi), rand(pi), rand(2 * pi))
296-
for 1 .. $iter;
312+
great_circle_distance(rand(pi), rand(2 * pi), rand(pi), rand(2 * pi))
313+
for 1 .. $iter;
297314
return $dist; # Returning something is optional, but is used to Fail bench on no match
298315
}
299316

@@ -303,8 +320,8 @@ with the default benchmarks:
303320
\&great_circle, # Reference to bench function
304321
'3144042.81433949', # Output for your reference Perl - determines Pass/Fail (optional)
305322
5.5, # Seconds to complete in normal mode for score = 1000 (optional)
306-
400000, # Argument to pass for --quick mode (optional)
307-
2000000 # Argument to pass for normal mode (optional)
323+
1000000, # Argument to pass for --quick mode (optional)
324+
5000000 # Argument to pass for normal mode (optional)
308325
]},
309326
}
310327
);
@@ -316,10 +333,21 @@ to run by itself:
316333

317334
my %stats = suite_run({
318335
include => 'custom',
319-
extra_bench => { custom1 => [sub {split //, 'x'x$_ for 1..10000}] }
336+
extra_bench => { custom1 => [sub {my @a=split(//, 'x'x$_) for 1..10000}] }
320337
}
321338
);
322339

340+
If you want to do a multi-threaded run as well and then calculate scalability:
341+
342+
my %stats_multi = suite_run({
343+
threads => system_identity(1);
344+
include => 'custom',
345+
extra_bench => { custom1 => [sub {my @a=split(//, 'x'x$_) for 1..10000}] }
346+
}
347+
);
348+
349+
my %scal = calc_scalability(\%stats, \%stats_multi);
350+
323351
# NOTES
324352

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

dkbench

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

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

87-
$opt{scale} ||= 1;
88-
($opt{time}, $opt{scale}) = (1, 1) if $opt{quick};
89-
9087
Benchmark::DKbench::Setup::fetch_genbank($opt{datapath}) if $opt{setup};
9188

9289
check_kit();
@@ -95,22 +92,17 @@ $max_threads = $opt{max_threads} if $opt{max_threads};
9592
$opt{threads} = $max_threads if $opt{multi} && $max_threads;
9693
$opt{threads} = 1 if ($opt{threads} && $opt{threads} < 0) || $opt{no_mce};
9794

98-
my $mce = $opt{no_mce} ? 'no MCE' :'MCE';
99-
10095
if ($opt{threads} || !$max_threads || $max_threads == 1) {
10196
$opt{threads} ||= 1;
102-
print "DKbench threads: $opt{threads} (".($opt{no_mce} ? 'no ':'')."MCE)\n";
10397
suite_run(\%opt);
10498
} else {
105-
print "DKbench single-thread run:\n";
10699
$opt{threads} = 1;
107100
my %stat1 = suite_run(\%opt);
108101
print (("-"x40)."\n");
109-
print "DKbench multi-thread run ($max_threads threads):\n";
110102
$opt{threads} = $max_threads;
111103
my %stat2 = suite_run(\%opt);
112104
print (("-"x40)."\n");
113-
calc_scalability(\%opt, \%stat1, \%stat2);
105+
calc_scalability(\%stat1, \%stat2);
114106
}
115107

116108
sub check_kit {

0 commit comments

Comments
 (0)