-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.pl
executable file
·157 lines (121 loc) · 3.97 KB
/
benchmark.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env perl
#
# This is the prototypical perl file; extend this with more best-practices
# when able.
use warnings;
use strict;
use Getopt::Long;
use Pod::Usage;
use Data::Dumper;
use File::Util;
File::Util::flock_rules( qw/ NOBLOCKEX IGNORE / );
# change the following to the top of your dev tree
use Find::Lib libs => ['../../common/perllib', '../common/perllib','.'];
use Chegg::Std;
use Chegg::Pipeline::Execute;
my($PROG) = $0 =~ m@/([^/]+)$@;
my($help, $man);
my($debug_tags) = '';
my($s) = Chegg::Std->new($PROG);
my(@verbose) = ();
my($e) = Chegg::Pipeline::Execute->new($PROG);
my($DATA_DIR) = '/Users/jric/dev/test/data';
my($VAR_DIR) = "$DATA_DIR/../var";
my(%BENCHMARKS) = (
'node0.8' => '/Users/jric/dev/test/js/test-IO-perf.js',
'python2' => '/Users/jric/dev/test/python/test_IO_perf.py'
);
my $NUM_RUNS = 20;
sub processCmdlineArgs {
Getopt::Long::Configure ("bundling");
my($args_ok) =
GetOptions (
'help|h' => \$help,
'man' => \$man,
'd|debug=s' => \$debug_tags,
'v|verbose' => \@verbose
);
if (!$args_ok) { pod2usage(); die "failed to process options"; }
if (defined($help)) { pod2usage(0); }
if (defined($man)) { pod2usage(-exitstatus => 0, -verbose => 2); }
(my @unexpected_args) = @ARGV;
if (0) { pod2usage('not enough args'); }
if (@unexpected_args) { pod2usage('too many args'); }
my($status) = $s->setDebug($debug_tags);
if ($status) { print STDOUT $status; exit(0); }
}
sub prepTest {
my($cmd) = "rm -r $VAR_DIR/news.yahoo.com";
my($status) = $e->execute_get_status($cmd);
if ($status->errors()) { return $status; }
$cmd = "cp -rp $DATA_DIR/news.yahoo.com $VAR_DIR/news.yahoo.com";
$status = $e->execute_get_status($cmd);
return $status;
}
# Runs benchmarks at given level of parallelism
# $timins_ref: will be populated like:
# { (node0.8|python2) => { <parallelism> => timings } }
sub runTest {
my($timings_ref, $parallel) = @_;
foreach my $benchmark ('node0.8', 'python2') {
my $run_time = 0;
my $cmd = $BENCHMARKS{$benchmark} .
" --parallel $parallel $VAR_DIR/news.yahoo.com";
for(my $count = 0; $count < $NUM_RUNS; $count++) {
my $status = prepTest();
if ($status->errors()) { return $status; }
my $time_start = time();
$status = $e->execute_get_status($cmd);
my $time_end = time();
if ($status->errors()) { return $status; }
$run_time += $time_end - $time_start;
}
$timings_ref->{$benchmark}->{$parallel} = $run_time;
}
return Chegg::Status->new();
}
sub runTests {
my %timings;
for(my $parallel = 1; $parallel < 200; ) {
my $status = runTest(\%timings, $parallel);
# last; # DEBUG
if ($parallel < 10) { $parallel++; }
elsif ($parallel < 100) { $parallel += 10; }
else { $parallel += 50; }
}
print "system\tparallelism\ttime\n";
foreach my $benchmark (keys(%timings)) {
foreach my $parallel (sort(keys(%{$timings{$benchmark}}))) {
print "$benchmark\t$parallel\t$timings{$benchmark}->{$parallel}\n";
}
}
return Chegg::Status->new();
}
sub main {
$s->announceMyself();
processCmdlineArgs();
my $status = runTests();
if ($status->errors()) { $s->error($status->errorMsg()); }
return $status->errors();
}
exit main();
__END__
=head1 benchmark.pl
benchmark.pl - run a node program and a python program with varying levels
of parallelism; run 20 trials at each level; prep before each trial;
record results
=head1 SYNOPSIS
benchmark.pl [options] [file ...]
REQUIRED ARGS:
OPTIONS:
GENERIC:
-h, --help : brief help message
--man : full documentation
-d, --debug [tag(s)] : see debug messages; special tags:
? : what are the possible debug tags I can use?
* : show me all possible debugging output
a,b : show me debugging output for both tags a and b
=head1 DESCRIPTION
B<This program> will read the given input file(s) and do something
useful with the contents thereof.
=cut