]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/perf/perldriver/PerfFramework.pm
2 # ***********************************************************************
4 # * Copyright (c) 2002-2004, International Business Machines Corporation
5 # * and others. All Rights Reserved.
6 # ***********************************************************************
16 my $start_l = ""; #formatting help
18 my @testArgs; # different kinds of tests we want to do
20 my $extraArgs; # stuff that always gets passed to the test program
26 my $ITERATIONS; #Added by Doug
30 my %options = %{shift @_};
32 if($options{"time"}) {
33 $TIME = $options{"time"};
36 if($options{"passes"}) {
37 $NUMPASSES = $options{"passes"};
40 if($options{"dataDir"}) {
41 $DATADIR = $options{"dataDir"};
45 if ($options{"iterations"}) {
46 $ITERATIONS = $options{"iterations"};
55 if($#_ >= 0) { # maybe no files/locales
56 my $datafiles = shift;
58 %datafiles = %{$datafiles};
61 setupOutput
($options);
62 setupOptions
($options);
64 my($locale, $iter, $data, $program, $args, $variable);
66 # Outer loop runs through the locales to test
69 foreach $locale (sort keys %datafiles ) {
70 foreach $data (@{ $datafiles{$locale} }) {
73 if(!($locale eq "")) {
74 $locdata = "<b>Locale:</b> $locale<br>";
76 $locdata .= "<b>Datafile:</b> $data<br>";
80 compareLoop
($tests, $locale, $DATADIR."/".$data);
82 compareLoop
($tests, $locale, $data);
94 #my @tests = @{$tests};
95 my %tests = %{$tests};
100 $locAndData .= " -L $locale";
103 $locAndData .= " -f $datafile";
108 foreach $i ( sort keys %tests ) {
118 for $j ( 0 .. $#{$aref} ) {
119 # first we calibrate. Use time from somewhere
120 # first test is used for calibration
121 ($program, @argsAndTest) = split(/\ /, @{ $tests{$i} }[$j]);
125 $commandLine = "$program -i $ITERATIONS -p $NUMPASSES $locAndData @argsAndTest";
127 $commandLine = "$program -t $TIME -p $NUMPASSES $locAndData @argsAndTest";
129 #my $commandLine = "$program -i 5 -p $NUMPASSES $locAndData @argsAndTest";
130 my @res = measure1
($commandLine);
131 store
("$i, $program @argsAndTest", @res);
133 push(@iterPerPass, shift(@res));
134 push(@noopers, shift(@res));
135 my @data = @{ shift(@res) };
137 push(@noevents, shift(@res));
141 shift(@data) if (@data > 1); # discard first run
143 #debug("data is @data\n");
144 my $ds = Dataset-
>new(@data);
146 push(@timedata, $ds);
149 outputRow
($i, \
@iterPerPass, \
@noopers, \
@timedata, \
@noevents);
154 #---------------------------------------------------------------------
155 # Measure a given test method with a give test pattern using the
156 # global run parameters.
158 # @param the method to run
159 # @param the pattern defining characters to test
160 # @param if >0 then the number of iterations per pass. If <0 then
161 # (negative of) the number of seconds per pass.
164 # [0] iterations per pass
165 # [1] events per iteration
166 # [2..] ms reported for each pass, in order
170 my @t = callProg
(shift); #"$program $args $argsAndTest");
174 # $a->[0]: method name, corresponds to $method
175 # $a->[1]: 'begin' data, == $iterCount
176 # $a->[2]: 'end' data, of the form <ms> <eventsPerIter>
177 # $a->[3...]: gc messages from JVM during pass
178 @b = split(/\s+/, $a->[2]);
180 push(@ms, shift(@b));
182 my $iterCount = shift(@b);
183 my $operationsPerIter = shift(@b);
186 $eventsPerIter = shift(@b);
189 # out("Iterations per pass: $iterCount<BR>\n");
190 # out("Events per iteration: $eventsPerIter<BR>\n");
191 # debug("Iterations per pass: $iterCount<BR>\n");
192 # if($eventsPerIter) {
193 # debug("Events per iteration: $eventsPerIter<BR>\n");
197 $ms_str[0] .= " (discarded)" if (@ms_str > 1);
198 # out("Raw times (ms/pass): ", join(", ", @ms_str), "<BR>\n");
199 debug
("Raw times (ms/pass): ", join(", ", @ms_str), "<BR>\n");
201 ($iterCount, $operationsPerIter, \
@ms, $eventsPerIter);
203 ($iterCount, $operationsPerIter, \
@ms);
209 #---------------------------------------------------------------------
210 # Measure a given test method with a give test pattern using the
211 # global run parameters.
213 # @param the method to run
214 # @param the pattern defining characters to test
215 # @param if >0 then the number of iterations per pass. If <0 then
216 # (negative of) the number of seconds per pass.
218 # @return a Dataset object, scaled by iterations per pass and
219 # events per iteration, to give time per event
222 my @res = measure1
(@_);
223 my $iterPerPass = shift(@res);
224 my $operationsPerIter = shift(@res);
225 my @data = @{ shift(@res) };
226 my $eventsPerIter = shift(@res);
229 shift(@data) if (@data > 1); # discard first run
231 my $ds = Dataset-
>new(@data);
232 #$ds->setScale(1.0e-3 / ($iterPerPass * $operationsPerIter));
233 ($ds, $iterPerPass, $operationsPerIter, $eventsPerIter);
237 #---------------------------------------------------------------------
238 # Invoke program and capture results, passing it the given parameters.
240 # @param the method to run
241 # @param the number of iterations, or if negative, the duration
242 # in seconds. If more than on pass is desired, pass in
243 # a string, e.g., "100 100 100".
244 # @param the pattern defining characters to test
246 # @return an array of results. Each result is an array REF
247 # describing one pass. The array REF contains:
248 # ->[0]: The method name as reported
249 # ->[1]: The params on the '= <meth> begin ...' line
250 # ->[2]: The params on the '= <meth> end ...' line
251 # ->[3..]: GC messages from the JVM, if any
258 #my $cmd = "java -cp c:\\dev\\myicu4j\\classes $TESTCLASS $method $n $pat";
259 debug
( "[$cmd]\n"); # for debugging
260 open(PIPE
, "$cmd|") or die "Can't run \"$cmd\"";
265 close(PIPE
) or die "Program failed: \"$cmd\"";
267 @out = grep(!/^\#/, @out); # filter out comments
269 #debug( "[", join("\n", @out), "]\n");
277 if (/^=\s*(\w+)\s*(\w+)\s*(.*)/) {
278 my ($m, $state, $d) = ($1, $2, $3);
279 #debug ("$_ => [[$m $state !!!$d!!! $data ]]\n");
280 if ($state eq 'begin') {
281 die "$method was begun but not finished" if ($method);
284 push(@$data, ''); # placeholder for end data
285 } elsif ($state eq 'end') {
287 die "$method end does not match: $_";
289 $data->[1] = $d; # insert end data at [1]
290 #debug( "#$method:", join(";",@$data), "\n");
291 unshift(@$data, $method); # add method to start
292 push(@results, $data);
296 die "Can't parse: $_";
304 # ignore extraneous GC notices
309 die "Can't parse: $_";
313 die "$method was begun but not finished" if ($method);
321 foreach $message (@_) {
322 print STDERR
"$message";
328 #Added here, was global
329 my $CALIBRATE = 2; # duration in seconds for initial calibration
333 my $iterCount = shift; # actually might be -seconds/pass
335 out
("<P>Measuring $method using $pat, ");
336 if ($iterCount > 0) {
337 out
("$iterCount iterations/pass, $NUMPASSES passes</P>\n");
339 out
(-$iterCount, " seconds/pass, $NUMPASSES passes</P>\n");
342 # is $iterCount actually -seconds?
343 if ($iterCount < 0) {
345 # calibrate: estimate ms/iteration
346 print "Calibrating...";
347 my @t = callJava
($method, $pat, -$CALIBRATE);
350 my @data = split(/\s+/, $t[0]->[2]);
351 my $timePerIter = 1.0e-3 * $data[0] / $data[2];
353 # determine iterations/pass
354 $iterCount = int(-$iterCount / $timePerIter + 0.5);
356 out
("<P>Calibration pass ($CALIBRATE sec): ");
357 out
("$data[0] ms, ");
358 out
("$data[2] iterations = ");
359 out
(formatSeconds
(4, $timePerIter), "/iteration<BR>\n");
363 print "Measuring $iterCount iterations x $NUMPASSES passes...";
364 my @t = callJava
($method, $pat, "$iterCount " x
$NUMPASSES);
369 # $a->[0]: method name, corresponds to $method
370 # $a->[1]: 'begin' data, == $iterCount
371 # $a->[2]: 'end' data, of the form <ms> <eventsPerIter>
372 # $a->[3...]: gc messages from JVM during pass
373 @b = split(/\s+/, $a->[2]);
376 my $eventsPerIter = $b[1];
378 out
("Iterations per pass: $iterCount<BR>\n");
379 out
("Events per iteration: $eventsPerIter<BR>\n");
382 $ms_str[0] .= " (discarded)" if (@ms_str > 1);
383 out
("Raw times (ms/pass): ", join(", ", @ms_str), "<BR>\n");
385 ($iterCount, $eventsPerIter, @ms);