Thu, 31 Aug 2017 15:30:47 +0800
merge
1 /*
2 * Copyright (c) 2010, 2013, 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 */
24 /**
25 * @subtest
26 */
28 var tests = [
29 {name:"box2d", files:["box2d.js"], suite:"Box2DBenchmark"},
30 {name:"code-load", files:["code-load.js"], suite:"CodeLoad"},
31 {name:"crypto", files:["crypto.js"], suite:"Crypto"},
32 {name:"deltablue", files:["deltablue.js"], suite:"DeltaBlue"},
33 {name:"earley-boyer", files:["earley-boyer.js"], suite:"EarleyBoyer"},
34 {name:"gbemu", files:["gbemu-part1.js", "gbemu-part2.js"], suite:"GameboyBenchmark"},
35 {name:"mandreel", files:["mandreel.js"], suite:"MandreelBenchmark"},
36 {name:"navier-stokes", files:["navier-stokes.js"], suite:"NavierStokes"},
37 {name:"pdfjs", files:["pdfjs.js"], suite:"PdfJS"},
38 {name:"raytrace", files:["raytrace.js"], suite:"RayTrace"},
39 {name:"regexp", files:["regexp.js"], suite:"RegExpSuite"},
40 {name:"richards", files:["richards.js"], suite:"Richards"},
41 {name:"splay", files:["splay.js"], suite:"Splay"},
42 {name:"typescript", files:["typescript.js", "typescript-input.js", "typescript-compiler.js"], suite:"typescript"}
43 //zlib currently disabled - requires read
44 // {name:"zlib", files:["zlib.js", "zlib-data.js"], suite:"zlib"},
45 ];
46 var dir = (typeof(__DIR__) == 'undefined') ? "test/script/basic/" : __DIR__;
48 // TODO: why is this path hard coded when it's defined in project properties?
49 var path = dir + "../external/octane/";
51 var runtime = "";
52 var verbose = false;
54 var numberOfIterations = 5;
56 function endsWith(str, suffix) {
57 return str.indexOf(suffix, str.length - suffix.length) !== -1;
58 }
60 function should_compile_only(name) {
61 return (typeof compile_only !== 'undefined')
62 }
64 function load_bench(arg) {
66 for (var idx = 0; idx < arg.files.length; idx++) {
67 var f = arg.files[idx];
68 var file = f.split('/');
69 var file_name = path + file[file.length - 1];
71 var compile_and_return = should_compile_only(file_name);
72 if (compile_and_return) {
73 if (typeof compile_only === 'undefined') { //for a run, skip compile onlies, don't even compile them
74 return true;
75 }
76 }
78 print_verbose(arg, "loading '" + arg.name + "' [" + f + "]...");
79 load(file_name);
80 }
82 if (compile_and_return) {
83 print_always(arg, "Compiled OK");
84 }
85 return !compile_and_return;
87 }
89 function run_one_benchmark(arg, iters) {
91 if (!load_bench(arg)) {
92 return;
93 }
95 var success = true;
96 var current_name;
98 if (iters == undefined) {
99 iters = numberOfIterations;
100 } else {
101 numberOfIterations = iters;
102 }
104 var benchmarks = eval(arg.suite + ".benchmarks");
105 var min_score = 1e9;
106 var max_score = 0;
107 var mean_score = 0;
109 try {
110 for (var x = 0; x < benchmarks.length ; x++) {
111 //do warmup run
112 //reset random number generator needed as of octane 9 before each run
113 BenchmarkSuite.ResetRNG();
114 benchmarks[x].Setup();
115 }
116 BenchmarkSuite.ResetRNG();
117 print_verbose(arg, "running '" + arg.name + "' for " + iters + " iterations of no less than " + min_time + " seconds (" + runtime + ")");
119 var scores = [];
121 var min_time_ms = min_time * 1000;
122 var len = benchmarks.length;
124 for (var it = 0; it < iters + 1; it++) {
125 //every iteration must take a minimum of 10 secs
126 var ops = 0;
127 var elapsed = 0;
128 var start = new Date;
129 do {
130 for (var i = 0; i < len; i++) {
131 benchmarks[i].run();
132 //important - no timing here like elapsed = new Date() - start, as in the
133 //original harness. This will make timing very non-deterministic.
134 //NOTHING else must live in this loop
135 }
136 ops += len;
137 elapsed = new Date - start;
138 } while (elapsed < min_time * 1000);
140 var score = ops / elapsed * 1000 * 60;
141 scores.push(score);
142 var name = it == 0 ? "warmup" : "iteration " + it;
143 print_verbose(arg, name + " finished " + score.toFixed(0) + " ops/minute");
144 }
146 for (var x = 0; x < benchmarks.length ; x++) {
147 benchmarks[x].TearDown();
148 }
150 for (var x = 1; x < iters + 1 ; x++) {
151 mean_score += scores[x];
152 min_score = Math.min(min_score, scores[x]);
153 max_score = Math.max(max_score, scores[x]);
154 }
155 mean_score /= iters;
157 } catch (e) {
158 print_always("*** Aborted and setting score to zero. Reason: " + e);
159 mean_score = min_score = max_score = 0;
160 scores = [0];
161 }
163 var res = mean_score.toFixed(0);
164 if (verbose) {
165 res += " ops/minute (" + min_score.toFixed(0) + "-" + max_score.toFixed(0) + "), warmup=" + scores[0].toFixed(0);
166 }
167 print_always(arg, res);
168 }
170 function print_always(arg, x) {
171 print("[" + arg.name + "] " + x);
172 }
174 function print_verbose(arg, x) {
175 if (verbose) {
176 print_always(arg, x)
177 }
178 }
180 function run_suite(tests, iters) {
181 for (var idx = 0; idx < tests.length; idx++) {
182 run_one_benchmark(tests[idx], iters);
183 }
184 }
186 runtime = "command line";
188 var args = [];
190 if (typeof $ARGS !== 'undefined') {
191 args = $ARGS;
192 } else if (typeof arguments !== 'undefined' && arguments.length != 0) {
193 args = arguments;
194 }
196 var new_args = [];
197 for (i in args) {
198 if (args[i].toString().indexOf(' ') != -1) {
199 args[i] = args[i].replace(/\/$/, '');
200 var s = args[i].split(' ');
201 for (j in s) {
202 new_args.push(s[j]);
203 }
204 } else {
205 new_args.push(args[i]);
206 }
207 }
209 if (new_args.length != 0) {
210 args = new_args;
211 }
213 var tests_found = [];
214 var iters = undefined;
215 var min_time = 5;
217 for (var i = 0; i < args.length; i++) {
218 arg = args[i];
219 if (arg == "--iterations") {
220 iters = +args[++i];
221 } else if (arg == "--runtime") {
222 runtime = args[++i];
223 } else if (arg == "--verbose") {
224 verbose = true;
225 } else if (arg == "--min-time") {
226 min_time = +args[++i];
227 } else if (arg == "") {
228 continue; //skip
229 } else {
230 var found = false;
231 for (j in tests) {
232 if (tests[j].name === arg) {
233 tests_found.push(tests[j]);
234 found = true;
235 break;
236 }
237 }
238 if (!found) {
239 var str = "unknown test name: '" + arg + "' -- valid names are: ";
240 for (j in tests) {
241 if (j != 0) {
242 str += ", ";
243 }
244 str += "'" + tests[j].name + "'";
245 }
246 throw str;
247 }
248 }
249 }
251 if (tests_found.length == 0) {
252 for (i in tests) {
253 tests_found.push(tests[i]);
254 }
255 }
257 tests_found.sort();
259 load(path + 'base.js');
260 run_suite(tests_found, iters);