test/script/basic/run-octane.js

changeset 3
da1e581c933b
child 7
5a1b0714df0e
equal deleted inserted replaced
2:6031a0bc0ae2 3:da1e581c933b
1 /*
2 * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /**
25 * @subtest
26 */
27
28 var tests = [
29 "box2d.js",
30 "code-load.js",
31 "crypto.js",
32 "deltablue.js",
33 "earley-boyer.js",
34 "gbemu.js",
35 "navier-stokes.js",
36 "pdfjs.js",
37 "raytrace.js",
38 "regexp.js",
39 "richards.js",
40 "splay.js"
41 ];
42
43 // hack, teardown breaks things defined in the global space, making it impossible
44 // to do multiple consecutive benchmark runs with the same harness. I think it's a bug
45 // that the setup and teardown aren't each others constructor and destructor but rather
46 // that the benchmarks rely on partial global state. For shame, Octane!
47 var ignoreTeardown = [
48 { name: "box2d.js" },
49 { name: "gbemu.js" },
50 ];
51
52 var dir = (typeof(__DIR__) == 'undefined') ? "test/script/basic/" : __DIR__;
53
54 // TODO: why is this path hard coded when it's defined in project properties?
55 var path = dir + "../external/octane/benchmarks/";
56
57 var runtime = "";
58 var verbose = false;
59
60 var numberOfIterations = 5;
61
62 function endsWith(str, suffix) {
63 return str.indexOf(suffix, str.length - suffix.length) !== -1;
64 }
65
66 function run_one_benchmark(arg, iters) {
67
68 load(path + 'base.js');
69 load(arg);
70
71 var file_name;
72
73 var file = arg.split('/');
74 if (file.length == 1) {
75 file = arg.split('\\');
76 }
77
78 //trim off trailing path separators
79 while (file[file.length - 1].indexOf(".js") == -1) {
80 file.pop();
81 }
82 file_name = file[file.length - 1];
83
84 if (typeof compile_only !== 'undefined') {
85 print("Compiled OK: " + file_name);
86 return;
87 }
88
89 var success = true;
90 var hiscore = 0;
91 var loscore = 10e8;
92 var current_name;
93
94 function PrintResult(name, result) {
95 current_name = name;
96 }
97
98 function PrintError(name, error) {
99 current_name = name;
100 PrintResult(name, error);
101 success = false;
102 }
103
104 function PrintScore(score) {
105 if (success) {
106 if (+score >= hiscore) {
107 hiscore = +score;
108 }
109 if (+score <= loscore) {
110 loscore = +score;
111 }
112 }
113
114 if (verbose) {
115 print("Score: " + score);
116 }
117 }
118
119 if (iters == undefined) {
120 iters = numberOfIterations;
121 } else {
122 numberOfIterations = iters;
123 }
124
125 print(runtime + ": running " + file_name + "...");
126
127 for (var i = 0; i < numberOfIterations; i++) {
128 var callbacks =
129 { NotifyResult: PrintResult,
130 NotifyError: PrintError,
131 NotifyScore: PrintScore };
132
133 for (j in ignoreTeardown) {
134 var ignore = ignoreTeardown[j];
135 if (endsWith(arg, ignore.name)) {
136 var teardownOverride = ignore.teardown;
137 if (!teardownOverride) {
138 teardownOverride = function() {};
139 }
140
141 for (k in BenchmarkSuite.suites) {
142 var benchmarks = BenchmarkSuite.suites[k].benchmarks;
143 for (l in benchmarks) {
144 benchmarks[l].TearDown = teardownOverride;
145 }
146 }
147 break;
148 }
149 }
150
151 BenchmarkSuite.RunSuites(callbacks);
152 }
153
154 var start = "Score: ";
155 if (runtime != "") {
156 start = runtime + ": ";
157 }
158 print(start + current_name + ' (version ' + BenchmarkSuite.version + '): ' + loscore + '-' + hiscore);
159 }
160
161 function run_suite(tests, iters) {
162 for (var idx = 0; idx < tests.length; idx++) {
163 run_one_benchmark(tests[idx], iters, false);
164 }
165 }
166
167 runtime = "command line";
168
169 var args = [];
170 if (typeof $ARGS !== 'undefined') {
171 args = $ARGS;
172 } else if (typeof arguments !== 'undefined' && arguments.length != 0) {
173 args = arguments;
174 }
175
176 var new_args = [];
177 for (i in args) {
178 if (args[i].toString().indexOf(' ') != -1) {
179 args[i] = args[i].replace(/\/$/, '');
180 var s = args[i].split(' ');
181 for (j in s) {
182 new_args.push(s[j]);
183 }
184 } else {
185 new_args.push(args[i]);
186 }
187 }
188
189 if (new_args.length != 0) {
190 args = new_args;
191 }
192
193 var tests_found = [];
194 var iters = undefined;
195
196 for (var i = 0; i < args.length; i++) {
197 arg = args[i];
198 if (arg == "--iterations") {
199 iters = +args[++i];
200 } else if (arg == "--runtime") {
201 runtime = args[++i];
202 } else if (arg == "--verbose") {
203 verbose = true;
204 } else if (arg == "") {
205 continue; //skip
206 } else {
207 tests_found.push(arg);
208 }
209 }
210
211 if (tests_found.length == 0) {
212 for (i in tests) {
213 tests_found.push(path + tests[i]);
214 }
215 }
216
217 tests_found.sort();
218
219 run_suite(tests_found, iters);
220
221
222

mercurial