]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/perf/perldriver/PerfFramework.pm
2 # ***********************************************************************
3 # * Copyright (C) 2016 and later: Unicode, Inc. and others.
4 # * License & terms of use: http://www.unicode.org/copyright.html#License
5 # ***********************************************************************
6 # ***********************************************************************
8 # * Copyright (c) 2002-2013, International Business Machines Corporation
9 # * and others. All Rights Reserved.
10 # ***********************************************************************
20 my $start_l = ""; #formatting help
22 my @testArgs; # different kinds of tests we want to do
24 my $extraArgs; # stuff that always gets passed to the test program
30 my $ITERATIONS; #Added by Doug
34 my %options = %{shift @_};
36 if($options{"time"}) {
37 $TIME = $options{"time"};
40 if($options{"passes"}) {
41 $NUMPASSES = $options{"passes"};
44 if($options{"dataDir"}) {
45 $DATADIR = $options{"dataDir"};
49 if ($options{"iterations"}) {
50 $ITERATIONS = $options{"iterations"};
59 if($#_ >= 0) { # maybe no files/locales
60 my $datafiles = shift;
62 %datafiles = %{$datafiles};
65 setupOutput
($options);
66 setupOptions
($options);
68 my($locale, $iter, $data, $program, $args, $variable);
70 # Outer loop runs through the locales to test
73 foreach $locale (sort keys %datafiles ) {
74 foreach $data (@{ $datafiles{$locale} }) {
77 if(!($locale eq "")) {
78 $locdata = "<b>Locale:</b> $locale<br>";
80 $locdata .= "<b>Datafile:</b> $data<br>";
84 compareLoop
($tests, $locale, $DATADIR."/".$data);
86 compareLoop
($tests, $locale, $data);
98 #my @tests = @{$tests};
99 my %tests = %{$tests};
101 my $datafile = shift;
104 $locAndData .= " -L \"$locale\"";
107 $locAndData .= " -f $datafile";
112 foreach $i ( sort keys %tests ) {
122 for $j ( 0 .. $#{$aref} ) {
123 # first we calibrate. Use time from somewhere
124 # first test is used for calibration
125 ($program, @argsAndTest) = split(/,/, @{ $tests{$i} }[$j]);
129 $commandLine = "$program -i $ITERATIONS -p $NUMPASSES $locAndData @argsAndTest";
131 $commandLine = "$program -t $TIME -p $NUMPASSES $locAndData @argsAndTest";
133 #my $commandLine = "$program -i 5 -p $NUMPASSES $locAndData @argsAndTest";
134 my @res = measure1
($commandLine);
135 store
("$i, $program @argsAndTest", @res);
137 push(@iterPerPass, shift(@res));
138 push(@noopers, shift(@res));
139 my @data = @{ shift(@res) };
141 push(@noevents, shift(@res));
144 shift(@data) if (@data > 1); # discard first run
146 #debug("data is @data\n");
147 my $ds = Dataset-
>new(@data);
149 push(@timedata, $ds);
152 outputRow
($i, \
@iterPerPass, \
@noopers, \
@timedata, \
@noevents);
157 #---------------------------------------------------------------------
158 # Measure a given test method with a give test pattern using the
159 # global run parameters.
161 # @param the method to run
162 # @param the pattern defining characters to test
163 # @param if >0 then the number of iterations per pass. If <0 then
164 # (negative of) the number of seconds per pass.
167 # [0] iterations per pass
168 # [1] events per iteration
169 # [2..] ms reported for each pass, in order
173 my @t = callProg
(shift); #"$program $args $argsAndTest");
177 # $a->[0]: method name, corresponds to $method
178 # $a->[1]: 'begin' data, == $iterCount
179 # $a->[2]: 'end' data, of the form <ms> <eventsPerIter>
180 # $a->[3...]: gc messages from JVM during pass
181 @b = split(/\s+/, $a->[2]);
183 push(@ms, shift(@b));
185 my $iterCount = shift(@b);
186 my $operationsPerIter = shift(@b);
189 $eventsPerIter = shift(@b);
192 # out("Iterations per pass: $iterCount<BR>\n");
193 # out("Events per iteration: $eventsPerIter<BR>\n");
194 # debug("Iterations per pass: $iterCount<BR>\n");
195 # if($eventsPerIter) {
196 # debug("Events per iteration: $eventsPerIter<BR>\n");
200 $ms_str[0] .= " (discarded)" if (@ms_str > 1);
201 # out("Raw times (ms/pass): ", join(", ", @ms_str), "<BR>\n");
202 debug
("Raw times (ms/pass): ", join(", ", @ms_str), "<BR>\n");
204 ($iterCount, $operationsPerIter, \
@ms, $eventsPerIter);
206 ($iterCount, $operationsPerIter, \
@ms);
212 #---------------------------------------------------------------------
213 # Measure a given test method with a give test pattern using the
214 # global run parameters.
216 # @param the method to run
217 # @param the pattern defining characters to test
218 # @param if >0 then the number of iterations per pass. If <0 then
219 # (negative of) the number of seconds per pass.
221 # @return a Dataset object, scaled by iterations per pass and
222 # events per iteration, to give time per event
225 my @res = measure1
(@_);
226 my $iterPerPass = shift(@res);
227 my $operationsPerIter = shift(@res);
228 my @data = @{ shift(@res) };
229 my $eventsPerIter = shift(@res);
232 shift(@data) if (@data > 1); # discard first run
234 my $ds = Dataset-
>new(@data);
235 #$ds->setScale(1.0e-3 / ($iterPerPass * $operationsPerIter));
236 ($ds, $iterPerPass, $operationsPerIter, $eventsPerIter);
240 #---------------------------------------------------------------------
241 # Invoke program and capture results, passing it the given parameters.
243 # @param the method to run
244 # @param the number of iterations, or if negative, the duration
245 # in seconds. If more than on pass is desired, pass in
246 # a string, e.g., "100 100 100".
247 # @param the pattern defining characters to test
249 # @return an array of results. Each result is an array REF
250 # describing one pass. The array REF contains:
251 # ->[0]: The method name as reported
252 # ->[1]: The params on the '= <meth> begin ...' line
253 # ->[2]: The params on the '= <meth> end ...' line
254 # ->[3..]: GC messages from the JVM, if any
261 #my $cmd = "java -cp c:\\dev\\myicu4j\\classes $TESTCLASS $method $n $pat";
262 debug
( "[$cmd]\n"); # for debugging
263 open(PIPE
, "$cmd|") or die "Can't run \"$cmd\"";
268 close(PIPE
) or die "Program failed: \"$cmd\"";
270 @out = grep(!/^\#/, @out); # filter out comments
272 #debug( "[", join("\n", @out), "]\n");
280 if (/^=\s*(\w+)\s*(\w+)\s*(.*)/) {
281 my ($m, $state, $d) = ($1, $2, $3);
282 #debug ("$_ => [[$m $state !!!$d!!! $data ]]\n");
283 if ($state eq 'begin') {
284 die "$method was begun but not finished" if ($method);
287 push(@$data, ''); # placeholder for end data
288 } elsif ($state eq 'end') {
290 die "$method end does not match: $_";
292 $data->[1] = $d; # insert end data at [1]
293 #debug( "#$method:", join(";",@$data), "\n");
294 unshift(@$data, $method); # add method to start
295 push(@results, $data);
299 die "Can't parse: $_";
307 # ignore extraneous GC notices
312 # die "Can't parse: $_";
316 die "$method was begun but not finished" if ($method);
324 foreach $message (@_) {
325 print STDERR
"$message";
331 #Added here, was global
332 my $CALIBRATE = 2; # duration in seconds for initial calibration
336 my $iterCount = shift; # actually might be -seconds/pass
338 out
("<P>Measuring $method using $pat, ");
339 if ($iterCount > 0) {
340 out
("$iterCount iterations/pass, $NUMPASSES passes</P>\n");
342 out
(-$iterCount, " seconds/pass, $NUMPASSES passes</P>\n");
345 # is $iterCount actually -seconds?
346 if ($iterCount < 0) {
348 # calibrate: estimate ms/iteration
349 print "Calibrating...";
350 my @t = callJava
($method, $pat, -$CALIBRATE);
353 my @data = split(/\s+/, $t[0]->[2]);
354 my $timePerIter = 1.0e-3 * $data[0] / $data[2];
356 # determine iterations/pass
357 $iterCount = int(-$iterCount / $timePerIter + 0.5);
359 out
("<P>Calibration pass ($CALIBRATE sec): ");
360 out
("$data[0] ms, ");
361 out
("$data[2] iterations = ");
362 out
(formatSeconds
(4, $timePerIter), "/iteration<BR>\n");
366 print "Measuring $iterCount iterations x $NUMPASSES passes...";
367 my @t = callJava
($method, $pat, "$iterCount " x
$NUMPASSES);
372 # $a->[0]: method name, corresponds to $method
373 # $a->[1]: 'begin' data, == $iterCount
374 # $a->[2]: 'end' data, of the form <ms> <eventsPerIter>
375 # $a->[3...]: gc messages from JVM during pass
376 @b = split(/\s+/, $a->[2]);
379 my $eventsPerIter = $b[1];
381 out
("Iterations per pass: $iterCount<BR>\n");
382 out
("Events per iteration: $eventsPerIter<BR>\n");
385 $ms_str[0] .= " (discarded)" if (@ms_str > 1);
386 out
("Raw times (ms/pass): ", join(", ", @ms_str), "<BR>\n");
388 ($iterCount, $eventsPerIter, @ms);