jlaskey@3: /* jlaskey@7: * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. jlaskey@3: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jlaskey@3: * jlaskey@3: * This code is free software; you can redistribute it and/or modify it jlaskey@3: * under the terms of the GNU General Public License version 2 only, as jlaskey@3: * published by the Free Software Foundation. jlaskey@3: * jlaskey@3: * This code is distributed in the hope that it will be useful, but WITHOUT jlaskey@3: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jlaskey@3: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jlaskey@3: * version 2 for more details (a copy is included in the LICENSE file that jlaskey@3: * accompanied this code). jlaskey@3: * jlaskey@3: * You should have received a copy of the GNU General Public License version jlaskey@3: * 2 along with this work; if not, write to the Free Software Foundation, jlaskey@3: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jlaskey@3: * jlaskey@3: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jlaskey@3: * or visit www.oracle.com if you need additional information or have any jlaskey@3: * questions. jlaskey@3: */ jlaskey@3: jlaskey@3: /** jlaskey@3: * @subtest jlaskey@3: */ jlaskey@3: jlaskey@3: var tests = [ jlaskey@3: "box2d.js", jlaskey@3: "code-load.js", jlaskey@3: "crypto.js", jlaskey@3: "deltablue.js", jlaskey@3: "earley-boyer.js", lagergren@139: "gbemu.js", lagergren@139: "mandreel.js", jlaskey@3: "navier-stokes.js", jlaskey@3: "pdfjs.js", jlaskey@3: "raytrace.js", jlaskey@3: "regexp.js", jlaskey@3: "richards.js", jlaskey@3: "splay.js" jlaskey@3: ]; jlaskey@3: jlaskey@3: // hack, teardown breaks things defined in the global space, making it impossible jlaskey@3: // to do multiple consecutive benchmark runs with the same harness. I think it's a bug jlaskey@3: // that the setup and teardown aren't each others constructor and destructor but rather jlaskey@3: // that the benchmarks rely on partial global state. For shame, Octane! jlaskey@3: var ignoreTeardown = [ jlaskey@3: { name: "box2d.js" }, jlaskey@3: { name: "gbemu.js" }, jlaskey@3: ]; jlaskey@3: lagergren@139: lagergren@139: //TODO mandreel can be compiled as a test, but not run multiple times unless modified to not have global state lagergren@139: var compileOnly = { lagergren@139: "mandreel.js" : true lagergren@139: }; lagergren@139: jlaskey@3: var dir = (typeof(__DIR__) == 'undefined') ? "test/script/basic/" : __DIR__; jlaskey@3: jlaskey@3: // TODO: why is this path hard coded when it's defined in project properties? sundar@19: var path = dir + "../external/octane/"; jlaskey@3: jlaskey@3: var runtime = ""; jlaskey@3: var verbose = false; jlaskey@3: jlaskey@3: var numberOfIterations = 5; jlaskey@3: jlaskey@3: function endsWith(str, suffix) { jlaskey@3: return str.indexOf(suffix, str.length - suffix.length) !== -1; jlaskey@3: } jlaskey@3: lagergren@139: function should_compile_only(name) { lagergren@139: return (typeof compile_only !== 'undefined') || compileOnly[name] === true; lagergren@139: } lagergren@139: jlaskey@3: function run_one_benchmark(arg, iters) { jlaskey@3: jlaskey@3: var file_name; jlaskey@3: var file = arg.split('/'); jlaskey@3: if (file.length == 1) { jlaskey@3: file = arg.split('\\'); jlaskey@3: } jlaskey@3: jlaskey@3: //trim off trailing path separators jlaskey@3: while (file[file.length - 1].indexOf(".js") == -1) { jlaskey@3: file.pop(); jlaskey@3: } jlaskey@3: file_name = file[file.length - 1]; lagergren@57: lagergren@139: var compile_and_return = should_compile_only(file_name); lagergren@139: if (compile_and_return) { lagergren@139: if (typeof compile_only === 'undefined') { //for a run, skip compile onlies, don't even compile them lagergren@139: return; lagergren@139: } lagergren@57: print("Compiling... " + file_name); lagergren@57: } lagergren@57: lagergren@57: load(path + 'base.js'); lagergren@57: load(arg); jlaskey@3: lagergren@139: if (compile_and_return) { jlaskey@3: print("Compiled OK: " + file_name); lagergren@57: print(""); jlaskey@3: return; jlaskey@3: } jlaskey@3: jlaskey@3: var success = true; jlaskey@3: var hiscore = 0; jlaskey@3: var loscore = 10e8; jlaskey@3: var current_name; jlaskey@3: jlaskey@3: function PrintResult(name, result) { jlaskey@3: current_name = name; jlaskey@3: } jlaskey@3: jlaskey@3: function PrintError(name, error) { jlaskey@3: current_name = name; jlaskey@3: PrintResult(name, error); jlaskey@3: success = false; jlaskey@3: } jlaskey@3: jlaskey@3: function PrintScore(score) { jlaskey@3: if (success) { jlaskey@3: if (+score >= hiscore) { jlaskey@3: hiscore = +score; jlaskey@3: } jlaskey@3: if (+score <= loscore) { jlaskey@3: loscore = +score; jlaskey@3: } jlaskey@3: } jlaskey@3: jlaskey@3: if (verbose) { jlaskey@3: print("Score: " + score); jlaskey@3: } jlaskey@3: } jlaskey@3: jlaskey@3: if (iters == undefined) { jlaskey@3: iters = numberOfIterations; jlaskey@3: } else { jlaskey@3: numberOfIterations = iters; jlaskey@3: } jlaskey@3: jlaskey@3: print(runtime + ": running " + file_name + "..."); jlaskey@3: jlaskey@3: for (var i = 0; i < numberOfIterations; i++) { jlaskey@3: var callbacks = jlaskey@3: { NotifyResult: PrintResult, jlaskey@3: NotifyError: PrintError, jlaskey@3: NotifyScore: PrintScore }; jlaskey@3: jlaskey@3: for (j in ignoreTeardown) { jlaskey@3: var ignore = ignoreTeardown[j]; jlaskey@3: if (endsWith(arg, ignore.name)) { jlaskey@3: var teardownOverride = ignore.teardown; jlaskey@3: if (!teardownOverride) { jlaskey@3: teardownOverride = function() {}; jlaskey@3: } jlaskey@3: jlaskey@3: for (k in BenchmarkSuite.suites) { jlaskey@3: var benchmarks = BenchmarkSuite.suites[k].benchmarks; jlaskey@3: for (l in benchmarks) { jlaskey@3: benchmarks[l].TearDown = teardownOverride; jlaskey@3: } jlaskey@3: } jlaskey@3: break; jlaskey@3: } jlaskey@3: } jlaskey@3: jlaskey@3: BenchmarkSuite.RunSuites(callbacks); jlaskey@3: } jlaskey@3: jlaskey@3: var start = "Score: "; jlaskey@3: if (runtime != "") { jlaskey@3: start = runtime + ": "; jlaskey@3: } jlaskey@3: print(start + current_name + ' (version ' + BenchmarkSuite.version + '): ' + loscore + '-' + hiscore); jlaskey@3: } jlaskey@3: jlaskey@3: function run_suite(tests, iters) { jlaskey@3: for (var idx = 0; idx < tests.length; idx++) { lagergren@139: run_one_benchmark(tests[idx], iters); jlaskey@3: } jlaskey@3: } jlaskey@3: jlaskey@3: runtime = "command line"; jlaskey@3: jlaskey@3: var args = []; jlaskey@3: if (typeof $ARGS !== 'undefined') { jlaskey@3: args = $ARGS; jlaskey@3: } else if (typeof arguments !== 'undefined' && arguments.length != 0) { jlaskey@3: args = arguments; jlaskey@3: } jlaskey@3: jlaskey@3: var new_args = []; jlaskey@3: for (i in args) { jlaskey@3: if (args[i].toString().indexOf(' ') != -1) { jlaskey@3: args[i] = args[i].replace(/\/$/, ''); jlaskey@3: var s = args[i].split(' '); jlaskey@3: for (j in s) { jlaskey@3: new_args.push(s[j]); jlaskey@3: } jlaskey@3: } else { jlaskey@3: new_args.push(args[i]); jlaskey@3: } jlaskey@3: } jlaskey@3: jlaskey@3: if (new_args.length != 0) { jlaskey@3: args = new_args; jlaskey@3: } jlaskey@3: jlaskey@3: var tests_found = []; jlaskey@3: var iters = undefined; jlaskey@3: jlaskey@3: for (var i = 0; i < args.length; i++) { jlaskey@3: arg = args[i]; jlaskey@3: if (arg == "--iterations") { jlaskey@3: iters = +args[++i]; jlaskey@3: } else if (arg == "--runtime") { jlaskey@3: runtime = args[++i]; jlaskey@3: } else if (arg == "--verbose") { jlaskey@3: verbose = true; jlaskey@3: } else if (arg == "") { jlaskey@3: continue; //skip jlaskey@3: } else { jlaskey@3: tests_found.push(arg); jlaskey@3: } jlaskey@3: } jlaskey@3: jlaskey@3: if (tests_found.length == 0) { jlaskey@3: for (i in tests) { jlaskey@3: tests_found.push(path + tests[i]); jlaskey@3: } jlaskey@3: } jlaskey@3: jlaskey@3: tests_found.sort(); jlaskey@3: jlaskey@3: run_suite(tests_found, iters); jlaskey@3: jlaskey@3: jlaskey@3: