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. attila@962: * 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. attila@962: * 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). attila@962: * 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. attila@962: * 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: */ hannesw@1034: var dir = typeof(__DIR__) == 'undefined' ? "test/script/basic/" : __DIR__; hannesw@1034: load(dir + "octane-payload.js"); jlaskey@3: attila@963: var runtime = undefined; 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@295: return (typeof compile_only !== 'undefined') lagergren@139: } lagergren@139: lagergren@693: function load_bench(arg) { lagergren@693: lagergren@693: for (var idx = 0; idx < arg.files.length; idx++) { hannesw@1034: var f = arg.files[idx]; hannesw@1034: var file = f.split('/'); hannesw@1034: var file_name = path + file[file.length - 1]; attila@962: hannesw@1034: var compile_and_return = should_compile_only(file_name); hannesw@1034: if (compile_and_return) { hannesw@1034: if (typeof compile_only === 'undefined') { //for a run, skip compile onlies, don't even compile them hannesw@1034: return true; hannesw@1034: } attila@962: } attila@962: hannesw@1034: print_verbose(arg, "loading '" + arg.name + "' [" + f + "]... " + file_name); hannesw@1034: load(file_name); lagergren@693: } lagergren@693: attila@963: if (typeof arg.before !== 'undefined') { hannesw@1034: arg.before(); attila@963: } attila@963: lagergren@693: if (compile_and_return) { hannesw@1034: print_always(arg, "Compiled OK"); lagergren@693: } lagergren@693: return !compile_and_return; lagergren@693: lagergren@693: } lagergren@693: attila@963: jlaskey@3: function run_one_benchmark(arg, iters) { lagergren@693: lagergren@693: if (!load_bench(arg)) { hannesw@1034: return; attila@962: } attila@962: jlaskey@3: var success = true; jlaskey@3: var current_name; attila@962: jlaskey@3: if (iters == undefined) { hannesw@1034: iters = numberOfIterations; jlaskey@3: } else { hannesw@1034: numberOfIterations = iters; jlaskey@3: } attila@962: lagergren@295: var benchmarks = eval(arg.suite + ".benchmarks"); lagergren@295: var min_score = 1e9; lagergren@295: var max_score = 0; lagergren@295: var mean_score = 0; lagergren@298: lagergren@298: try { hannesw@1034: for (var x = 0; x < benchmarks.length ; x++) { hannesw@1034: //do warmup run hannesw@1034: //reset random number generator needed as of octane 9 before each run hannesw@1034: BenchmarkSuite.ResetRNG(); hannesw@1034: benchmarks[x].Setup(); hannesw@1034: } attila@962: BenchmarkSuite.ResetRNG(); hannesw@1034: print_verbose(arg, "running '" + arg.name + "' for " + iters + " iterations of no less than " + min_time + " seconds"); lagergren@298: hannesw@1034: var scores = []; lagergren@298: hannesw@1034: var min_time_ms = min_time * 1000; hannesw@1034: var len = benchmarks.length; attila@962: hannesw@1034: for (var it = 0; it < iters + 1; it++) { hannesw@1034: //every iteration must take a minimum of 10 secs hannesw@1034: var ops = 0; hannesw@1034: var elapsed = 0; hannesw@1034: var start = new Date; hannesw@1034: do { hannesw@1034: for (var i = 0; i < len; i++) { hannesw@1034: benchmarks[i].run(); hannesw@1034: //important - no timing here like elapsed = new Date() - start, as in the hannesw@1034: //original harness. This will make timing very non-deterministic. hannesw@1034: //NOTHING else must live in this loop hannesw@1034: } hannesw@1034: ops += len; hannesw@1034: elapsed = new Date - start; hannesw@1034: } while (elapsed < min_time * 1000); hannesw@1034: hannesw@1034: var score = ops / elapsed * 1000 * 60; hannesw@1034: scores.push(score); hannesw@1034: var name = it == 0 ? "warmup" : "iteration " + it; hannesw@1034: print_verbose(arg, name + " finished " + score.toFixed(0) + " ops/minute"); hannesw@1034: hannesw@1034: // optional per-iteration cleanup hook hannesw@1034: if (typeof arg.cleanUpIteration == "function") { hannesw@1034: arg.cleanUpIteration(); hannesw@1034: } attila@962: } attila@962: hannesw@1034: for (var x = 0; x < benchmarks.length ; x++) { hannesw@1034: benchmarks[x].TearDown(); hannesw@1034: } attila@962: hannesw@1034: for (var x = 1; x < iters + 1 ; x++) { hannesw@1034: mean_score += scores[x]; hannesw@1034: min_score = Math.min(min_score, scores[x]); hannesw@1034: max_score = Math.max(max_score, scores[x]); hannesw@1034: } hannesw@1034: mean_score /= iters; lagergren@298: } catch (e) { hannesw@1034: print_always(arg, "*** Aborted and setting score to zero. Reason: " + e); hannesw@1034: if (is_this_nashorn() && e instanceof java.lang.Throwable) { hannesw@1034: e.printStackTrace(); hannesw@1034: } hannesw@1034: mean_score = min_score = max_score = 0; hannesw@1034: scores = [0]; lagergren@295: } lagergren@298: lagergren@693: var res = mean_score.toFixed(0); lagergren@295: if (verbose) { hannesw@1034: res += " ops/minute (" + min_score.toFixed(0) + "-" + max_score.toFixed(0) + "), warmup=" + scores[0].toFixed(0); lagergren@295: } lagergren@693: print_always(arg, res); lagergren@295: } jlaskey@3: attila@963: function runtime_string() { attila@963: return runtime == undefined ? "" : ("[" + runtime + "] "); attila@963: } attila@963: lagergren@693: function print_always(arg, x) { attila@963: print(runtime_string() + "[" + arg.name + "] " + x); lagergren@295: } jlaskey@3: lagergren@693: function print_verbose(arg, x) { lagergren@295: if (verbose) { hannesw@1034: print_always(arg, x) jlaskey@3: } jlaskey@3: } jlaskey@3: jlaskey@3: function run_suite(tests, iters) { jlaskey@3: for (var idx = 0; idx < tests.length; idx++) { hannesw@1034: run_one_benchmark(tests[idx], iters); jlaskey@3: } jlaskey@3: } jlaskey@3: jlaskey@3: var args = []; lagergren@298: jlaskey@3: if (typeof $ARGS !== 'undefined') { jlaskey@3: args = $ARGS; jlaskey@3: } else if (typeof arguments !== 'undefined' && arguments.length != 0) { jlaskey@3: args = arguments; attila@962: } jlaskey@3: jlaskey@3: var new_args = []; jlaskey@3: for (i in args) { jlaskey@3: if (args[i].toString().indexOf(' ') != -1) { hannesw@1034: args[i] = args[i].replace(/\/$/, ''); hannesw@1034: var s = args[i].split(' '); hannesw@1034: for (j in s) { hannesw@1034: new_args.push(s[j]); hannesw@1034: } jlaskey@3: } else { hannesw@1034: 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; lagergren@295: var min_time = 5; jlaskey@3: attila@962: for (var i = 0; i < args.length; i++) { jlaskey@3: arg = args[i]; jlaskey@3: if (arg == "--iterations") { hannesw@1034: iters = +args[++i]; hannesw@1034: if (isNaN(iters)) { hannesw@1034: throw "'--iterations' must be followed by integer"; hannesw@1034: } jlaskey@3: } else if (arg == "--runtime") { hannesw@1034: runtime = args[++i]; jlaskey@3: } else if (arg == "--verbose") { hannesw@1034: verbose = true; lagergren@295: } else if (arg == "--min-time") { hannesw@1034: min_time = +args[++i]; hannesw@1034: if (isNaN(iters)) { hannesw@1034: throw "'--min-time' must be followed by integer"; hannesw@1034: } jlaskey@3: } else if (arg == "") { hannesw@1034: continue; //skip jlaskey@3: } else { hannesw@1034: var found = false; hannesw@1034: for (j in tests) { hannesw@1034: if (tests[j].name === arg) { hannesw@1034: tests_found.push(tests[j]); hannesw@1034: found = true; hannesw@1034: break; hannesw@1034: } attila@962: } hannesw@1034: if (!found) { hannesw@1034: var str = "unknown test name: '" + arg + "' -- valid names are: "; hannesw@1034: for (j in tests) { hannesw@1034: if (j != 0) { hannesw@1034: str += ", "; hannesw@1034: } hannesw@1034: str += "'" + tests[j].name + "'"; hannesw@1034: } hannesw@1034: throw str; attila@962: } jlaskey@3: } jlaskey@3: } jlaskey@3: attila@962: if (tests_found.length == 0) { jlaskey@3: for (i in tests) { hannesw@1034: tests_found.push(tests[i]); jlaskey@3: } attila@962: } jlaskey@3: attila@963: // returns false for rhino, v8 and all other javascript runtimes, true for Nashorn attila@963: function is_this_nashorn() { attila@963: return typeof Error.dumpStack == 'function' attila@963: } attila@963: attila@963: if (is_this_nashorn()) { attila@963: try { hannesw@1034: read = readFully; attila@963: } catch (e) { hannesw@1034: print("ABORTING: Cannot find 'readFully'. You must have scripting enabled to use this test harness. (-scripting)"); hannesw@1034: throw e; attila@963: } attila@963: } attila@963: attila@963: // run tests in alphabetical order by name attila@963: tests_found.sort(function(a, b) { attila@963: if (a.name < b.name) { hannesw@1034: return -1; attila@963: } else if (a.name > b.name) { hannesw@1034: return 1; attila@963: } else { hannesw@1034: return 0; attila@963: } attila@963: }); jlaskey@3: lagergren@295: load(path + 'base.js'); jlaskey@3: run_suite(tests_found, iters);