forked from pozorvlak/Benchmark-PriorityQueue
/
bmark_pq
executable file
·71 lines (58 loc) · 1.66 KB
/
bmark_pq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/perl
use strict;
use warnings;
use 5.10.0;
use Benchmark::PriorityQueue qw'run_all_benchmarks run_benchmark';
use Getopt::Long;
use DateTime::Duration;
my $default_n = 3;
my @modules; my @benchmarks; my $help; my $timeout;
my $n = $default_n;
GetOptions ("m=s" => \@modules,
"b=s" => \@benchmarks,
"n=i" => \$n,
"t=i" => \$timeout,
"help|?|h" => \$help)
or usage(2);
if ($help) {
usage(0);
}
usage(2) if @ARGV;
$timeout = DateTime::Duration->new(seconds => $timeout // 0);
if (@benchmarks == 0) {
run_all_benchmarks($n, $timeout, @modules);
} else {
for my $bmark (@benchmarks) {
run_benchmark($bmark, $n, $timeout, @modules);
}
}
sub usage {
my ($status) = @_;
select STDERR if $status != 0;
say <<END;
Usage:
$0 -n [exp] -t [timeout] -m [module 1] -m [module 2] -b [benchmark 1] ...
Options:
-m Module to benchmark, eg List::Priority. If no -m options are given, all
priority queue modules are benchmarked.
-b Benchmark to run. If no -b options are given, all benchmarks are run.
-n Maximum exponent to use. For example, if -n 3 is used, data-structures
of at most 1000 elements (= 10^3) are used for benchmarking.
Defaults to $default_n.
-t Timeout in seconds. If this time is exceeded for a given
benchmark/module pair, we give up and move on to the next one.
END
print_benchmarks();
say "";
print_modules();
say "";
exit $status;
}
sub print_benchmarks {
say "Available benchmarks:";
print(map { " $_\n" } Benchmark::PriorityQueue::all_benchmarks());
}
sub print_modules {
say "Available modules to benchmark:";
print(map { " $_\n" } Benchmark::PriorityQueue::all_tested_modules());
}