-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbench-more.pl
executable file
·82 lines (67 loc) · 1.62 KB
/
bench-more.pl
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
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/perl
use warnings;
use strict;
use MIME::Base64;
sub maxlen {
return (sort { $a <=> $b } map { length } @_)[-1];
}
sub usage {
die <<EOF;
usage: $0 <count> <prog>... -- <input>...
EOF
}
usage if @ARGV < 4 or $ARGV[0] !~ m{^\d+$};
my $count = shift;
my @prog;
push @prog, shift while @ARGV and $ARGV[0] ne '--';
usage if '--' ne shift @ARGV;
my @file = @ARGV;
my $wp = maxlen @prog;
my $wf = maxlen @file, "0.000";
my $waf = ($wf+1) * scalar @file;
my %stats;
open my $rnd, '<', '/dev/urandom'
or die "open /dev/urandom: $!\n";
for (my $N = 1 ;; ++$N) {
my $seed;
sysread $rnd, $seed, 12;
$seed = encode_base64 $seed, "";
for my $file (@file) {
for my $prog (@prog) {
print "$prog $seed $count $file\n";
for (qx{$prog $seed $count $file}) {
if(m{^(\w+)... ([0-9.]+) s$}) {
my $test = $1;
my $time = $2;
$stats{$test}{$prog}{$file}{this} = $time;
$stats{$test}{$prog}{$file}{min} = $time
if not defined $stats{$test}{$prog}{$file}{min}
or $stats{$test}{$prog}{$file}{min} > $time;
$stats{$test}{$prog}{$file}{tot} += $time;
$stats{$test}{$prog}{$file}{tot2} += $time * $time;
}
}
}
}
printf "round $N\n";
printf "%-*s ", $wp, "";
printf "| %-*s", $waf, $_ for sort keys %stats;
print "\n";
printf "%-*s", $wp, "";
for (sort keys %stats) {
printf " |";
printf " %*s", $wf, $_ for @file;
}
print "\n";
for my $prog (@prog) {
printf "%-*s", $wp, $prog;
for my $test (sort keys %stats) {
printf " |";
for my $file (@file) {
my $mean = $stats{$test}{$prog}{$file}{tot} / $N;
printf " %*.3f", $wf, $mean;
}
}
print "\n";
}
}