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