blob: a34f796ad5865529c9782636a9e12f5161fa4bb1 [file] [log] [blame]
mjs1151ff22007-10-23 22:27:42 +00001#!/usr/bin/perl -w
2
darin46738432007-10-28 23:08:44 +00003# Copyright (C) 2007 Apple Inc. All rights reserved.
mjs1151ff22007-10-23 22:27:42 +00004#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8# 1. Redistributions of source code must retain the above copyright
9# notice, this list of conditions and the following disclaimer.
10# 2. Redistributions in binary form must reproduce the above copyright
11# notice, this list of conditions and the following disclaimer in the
12# documentation and/or other materials provided with the distribution.
13#
14# THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
26use strict;
mjs69fe8b62007-10-24 00:40:35 +000027use Getopt::Long;
mjs1151ff22007-10-23 22:27:42 +000028use File::Basename;
29
mjs69fe8b62007-10-24 00:40:35 +000030my $showHelp = 0;
31my $jsShellPath;
bfulgham@webkit.orgcbfd3572009-05-27 00:29:29 +000032my $ubench = 0;
33my $v8suite = 0;
treat@webkit.orgc47eff92009-06-19 20:57:33 +000034my $parseonly = 0;
mjs69fe8b62007-10-24 00:40:35 +000035
mjs1151ff22007-10-23 22:27:42 +000036my $programName = basename($0);
37my $usage = <<EOF;
mjs69fe8b62007-10-24 00:40:35 +000038Usage: $programName --shell=[path] [options] FILE FILE
39 --help Show this help message
40 --shell Path to javascript shell
bfulgham@webkit.orgcbfd3572009-05-27 00:29:29 +000041 --ubench Compare microbenchmark results
42 --v8-suite Compare the V8 benchmark results
treat@webkit.orgc47eff92009-06-19 20:57:33 +000043 --parse-only Compare the parse-only benchmark results
mjs1151ff22007-10-23 22:27:42 +000044EOF
45
mjs69fe8b62007-10-24 00:40:35 +000046GetOptions('shell=s' => \$jsShellPath,
bfulgham@webkit.orgcbfd3572009-05-27 00:29:29 +000047 'ubench' => \$ubench,
48 'v8-suite' => \$v8suite,
treat@webkit.orgc47eff92009-06-19 20:57:33 +000049 'parse-only' => \$parseonly,
mjs69fe8b62007-10-24 00:40:35 +000050 'help' => \$showHelp);
51
bfulgham@webkit.orgcbfd3572009-05-27 00:29:29 +000052my $resultDirectory = "sunspider-results";
53$resultDirectory = "ubench-results" if ($ubench);
54$resultDirectory = "v8-results" if ($v8suite);
treat@webkit.orgc47eff92009-06-19 20:57:33 +000055$resultDirectory = "parse-only-results" if ($parseonly);
bfulgham@webkit.orgcbfd3572009-05-27 00:29:29 +000056
darin@apple.com41a7c172007-11-03 00:15:02 +000057if ((scalar @ARGV != 0 && scalar @ARGV != 2) || !$jsShellPath || $showHelp) {
mjs69fe8b62007-10-24 00:40:35 +000058 print STDERR $usage;
59 exit 1;
mjs1151ff22007-10-23 22:27:42 +000060}
61
62sub readResultsFile($)
63{
64 my ($filename) = @_;
darinf7756ca2007-10-24 07:41:45 +000065 open FILE, "<", $filename or die;
mjs1151ff22007-10-23 22:27:42 +000066 my $foundStart = 0;
darin46738432007-10-28 23:08:44 +000067 my $foundOutput = 0;
mjs1151ff22007-10-23 22:27:42 +000068 my $foundEnd = 0;
69 my $result = "";
70 while (<FILE>) {
71 if (!$foundStart) {
darin46738432007-10-28 23:08:44 +000072 if (/^\[\{$/) {
73 $foundStart = 1;
74 $result .= $_;
75 } elsif (/^var \w+ = \[$/) {
76 $foundOutput = 1;
77 } elsif ($foundOutput && /^\{$/) {
78 $foundOutput = 0;
79 $foundStart = 1;
80 $result = "[{\n";
81 }
82 } else {
83 if (/\];?$/) {
84 $foundEnd = 1;
85 chomp;
86 s/;$//;
87 $result .= $_;
88 last;
89 } else {
90 $result .= $_;
91 }
92 }
mjs1151ff22007-10-23 22:27:42 +000093 }
94 close FILE;
95
mjsc71c0a82007-10-30 01:55:13 +000096 die "Cound not find data in ${filename} - needs to start with [{" unless $foundStart;
97 die "Cound not find data in ${filename} - needs to end with }]" unless $foundEnd;
mjs1151ff22007-10-23 22:27:42 +000098
99 return $result;
100}
101
102sub dumpToFile($$)
103{
104 my ($contents, $path) = @_;
darinf7756ca2007-10-24 07:41:45 +0000105 open FILE, ">", $path or die;
mjs1151ff22007-10-23 22:27:42 +0000106 print FILE $contents;
107 close FILE;
108}
109
darin@apple.com41a7c172007-11-03 00:15:02 +0000110sub readFile($)
111{
112 my ($path) = @_;
113 open FILE, "<", $path or die;
114 my $result = <FILE>;
115 close FILE;
116 return $result;
117}
118
119sub newestFile($$)
120{
121 my ($dir, $pattern) = @_;
122
123 my $newestAge;
124 my $newestFile = "";
125 opendir DIR, $dir or die;
126 for my $file (readdir DIR) {
127 if ($file =~ $pattern) {
128 my $age = -M "$dir/$file";
129 if (!defined $newestAge || $age < $newestAge) {
130 $newestFile = $file;
131 $newestAge = $age;
132 }
133 }
134 }
135 closedir DIR;
136
137 return "$dir/$newestFile";
138}
139
140my $file1;
141my $file2;
142
143if (scalar @ARGV == 2) {
144 $file1 = $ARGV[0];
145 $file2 = $ARGV[1];
146} else {
bfulgham@webkit.orgcbfd3572009-05-27 00:29:29 +0000147 $file1 = readFile("$resultDirectory/baseline-filename.txt");
148 $file2 = newestFile("$resultDirectory", qr/sunspider-results-.+\.js$/);
darin@apple.com41a7c172007-11-03 00:15:02 +0000149}
150
151my $output = "var output1 = " . readResultsFile($file1) . ";\n";
152$output .= "var output2 = " . readResultsFile($file2) . ";\n";
mjs1151ff22007-10-23 22:27:42 +0000153
bfulgham@webkit.orgcbfd3572009-05-27 00:29:29 +0000154dumpToFile($output, "$resultDirectory/sunspider-comparison-data.js");
mjs1151ff22007-10-23 22:27:42 +0000155
bfulgham@webkit.orgcbfd3572009-05-27 00:29:29 +0000156system($jsShellPath, "-f", "$resultDirectory/sunspider-test-prefix.js", "-f", "$resultDirectory/sunspider-comparison-data.js", "-f", "resources/sunspider-compare-results.js", "-f", "resources/sunspider-standalone-compare.js");