test/script/basic/run-octane.js

Tue, 21 Mar 2017 13:41:57 -0700

author
asaha
date
Tue, 21 Mar 2017 13:41:57 -0700
changeset 2160
1df40fe54cd6
parent 1034
5d41c7482d54
child 1205
4112748288bb
permissions
-rw-r--r--

Merge

jlaskey@3 1 /*
jlaskey@7 2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
jlaskey@3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
attila@962 4 *
jlaskey@3 5 * This code is free software; you can redistribute it and/or modify it
jlaskey@3 6 * under the terms of the GNU General Public License version 2 only, as
jlaskey@3 7 * published by the Free Software Foundation.
attila@962 8 *
jlaskey@3 9 * This code is distributed in the hope that it will be useful, but WITHOUT
jlaskey@3 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jlaskey@3 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jlaskey@3 12 * version 2 for more details (a copy is included in the LICENSE file that
jlaskey@3 13 * accompanied this code).
attila@962 14 *
jlaskey@3 15 * You should have received a copy of the GNU General Public License version
jlaskey@3 16 * 2 along with this work; if not, write to the Free Software Foundation,
jlaskey@3 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
attila@962 18 *
jlaskey@3 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jlaskey@3 20 * or visit www.oracle.com if you need additional information or have any
jlaskey@3 21 * questions.
jlaskey@3 22 */
jlaskey@3 23
jlaskey@3 24 /**
jlaskey@3 25 * @subtest
jlaskey@3 26 */
hannesw@1034 27 var dir = typeof(__DIR__) == 'undefined' ? "test/script/basic/" : __DIR__;
hannesw@1034 28 load(dir + "octane-payload.js");
jlaskey@3 29
attila@963 30 var runtime = undefined;
jlaskey@3 31 var verbose = false;
jlaskey@3 32
jlaskey@3 33 var numberOfIterations = 5;
jlaskey@3 34
jlaskey@3 35 function endsWith(str, suffix) {
jlaskey@3 36 return str.indexOf(suffix, str.length - suffix.length) !== -1;
jlaskey@3 37 }
jlaskey@3 38
lagergren@139 39 function should_compile_only(name) {
lagergren@295 40 return (typeof compile_only !== 'undefined')
lagergren@139 41 }
lagergren@139 42
lagergren@693 43 function load_bench(arg) {
lagergren@693 44
lagergren@693 45 for (var idx = 0; idx < arg.files.length; idx++) {
hannesw@1034 46 var f = arg.files[idx];
hannesw@1034 47 var file = f.split('/');
hannesw@1034 48 var file_name = path + file[file.length - 1];
attila@962 49
hannesw@1034 50 var compile_and_return = should_compile_only(file_name);
hannesw@1034 51 if (compile_and_return) {
hannesw@1034 52 if (typeof compile_only === 'undefined') { //for a run, skip compile onlies, don't even compile them
hannesw@1034 53 return true;
hannesw@1034 54 }
attila@962 55 }
attila@962 56
hannesw@1034 57 print_verbose(arg, "loading '" + arg.name + "' [" + f + "]... " + file_name);
hannesw@1034 58 load(file_name);
lagergren@693 59 }
lagergren@693 60
attila@963 61 if (typeof arg.before !== 'undefined') {
hannesw@1034 62 arg.before();
attila@963 63 }
attila@963 64
lagergren@693 65 if (compile_and_return) {
hannesw@1034 66 print_always(arg, "Compiled OK");
lagergren@693 67 }
lagergren@693 68 return !compile_and_return;
lagergren@693 69
lagergren@693 70 }
lagergren@693 71
attila@963 72
jlaskey@3 73 function run_one_benchmark(arg, iters) {
lagergren@693 74
lagergren@693 75 if (!load_bench(arg)) {
hannesw@1034 76 return;
attila@962 77 }
attila@962 78
jlaskey@3 79 var success = true;
jlaskey@3 80 var current_name;
attila@962 81
jlaskey@3 82 if (iters == undefined) {
hannesw@1034 83 iters = numberOfIterations;
jlaskey@3 84 } else {
hannesw@1034 85 numberOfIterations = iters;
jlaskey@3 86 }
attila@962 87
lagergren@295 88 var benchmarks = eval(arg.suite + ".benchmarks");
lagergren@295 89 var min_score = 1e9;
lagergren@295 90 var max_score = 0;
lagergren@295 91 var mean_score = 0;
lagergren@298 92
lagergren@298 93 try {
hannesw@1034 94 for (var x = 0; x < benchmarks.length ; x++) {
hannesw@1034 95 //do warmup run
hannesw@1034 96 //reset random number generator needed as of octane 9 before each run
hannesw@1034 97 BenchmarkSuite.ResetRNG();
hannesw@1034 98 benchmarks[x].Setup();
hannesw@1034 99 }
attila@962 100 BenchmarkSuite.ResetRNG();
hannesw@1034 101 print_verbose(arg, "running '" + arg.name + "' for " + iters + " iterations of no less than " + min_time + " seconds");
lagergren@298 102
hannesw@1034 103 var scores = [];
lagergren@298 104
hannesw@1034 105 var min_time_ms = min_time * 1000;
hannesw@1034 106 var len = benchmarks.length;
attila@962 107
hannesw@1034 108 for (var it = 0; it < iters + 1; it++) {
hannesw@1034 109 //every iteration must take a minimum of 10 secs
hannesw@1034 110 var ops = 0;
hannesw@1034 111 var elapsed = 0;
hannesw@1034 112 var start = new Date;
hannesw@1034 113 do {
hannesw@1034 114 for (var i = 0; i < len; i++) {
hannesw@1034 115 benchmarks[i].run();
hannesw@1034 116 //important - no timing here like elapsed = new Date() - start, as in the
hannesw@1034 117 //original harness. This will make timing very non-deterministic.
hannesw@1034 118 //NOTHING else must live in this loop
hannesw@1034 119 }
hannesw@1034 120 ops += len;
hannesw@1034 121 elapsed = new Date - start;
hannesw@1034 122 } while (elapsed < min_time * 1000);
hannesw@1034 123
hannesw@1034 124 var score = ops / elapsed * 1000 * 60;
hannesw@1034 125 scores.push(score);
hannesw@1034 126 var name = it == 0 ? "warmup" : "iteration " + it;
hannesw@1034 127 print_verbose(arg, name + " finished " + score.toFixed(0) + " ops/minute");
hannesw@1034 128
hannesw@1034 129 // optional per-iteration cleanup hook
hannesw@1034 130 if (typeof arg.cleanUpIteration == "function") {
hannesw@1034 131 arg.cleanUpIteration();
hannesw@1034 132 }
attila@962 133 }
attila@962 134
hannesw@1034 135 for (var x = 0; x < benchmarks.length ; x++) {
hannesw@1034 136 benchmarks[x].TearDown();
hannesw@1034 137 }
attila@962 138
hannesw@1034 139 for (var x = 1; x < iters + 1 ; x++) {
hannesw@1034 140 mean_score += scores[x];
hannesw@1034 141 min_score = Math.min(min_score, scores[x]);
hannesw@1034 142 max_score = Math.max(max_score, scores[x]);
hannesw@1034 143 }
hannesw@1034 144 mean_score /= iters;
lagergren@298 145 } catch (e) {
hannesw@1034 146 print_always(arg, "*** Aborted and setting score to zero. Reason: " + e);
hannesw@1034 147 if (is_this_nashorn() && e instanceof java.lang.Throwable) {
hannesw@1034 148 e.printStackTrace();
hannesw@1034 149 }
hannesw@1034 150 mean_score = min_score = max_score = 0;
hannesw@1034 151 scores = [0];
lagergren@295 152 }
lagergren@298 153
lagergren@693 154 var res = mean_score.toFixed(0);
lagergren@295 155 if (verbose) {
hannesw@1034 156 res += " ops/minute (" + min_score.toFixed(0) + "-" + max_score.toFixed(0) + "), warmup=" + scores[0].toFixed(0);
lagergren@295 157 }
lagergren@693 158 print_always(arg, res);
lagergren@295 159 }
jlaskey@3 160
attila@963 161 function runtime_string() {
attila@963 162 return runtime == undefined ? "" : ("[" + runtime + "] ");
attila@963 163 }
attila@963 164
lagergren@693 165 function print_always(arg, x) {
attila@963 166 print(runtime_string() + "[" + arg.name + "] " + x);
lagergren@295 167 }
jlaskey@3 168
lagergren@693 169 function print_verbose(arg, x) {
lagergren@295 170 if (verbose) {
hannesw@1034 171 print_always(arg, x)
jlaskey@3 172 }
jlaskey@3 173 }
jlaskey@3 174
jlaskey@3 175 function run_suite(tests, iters) {
jlaskey@3 176 for (var idx = 0; idx < tests.length; idx++) {
hannesw@1034 177 run_one_benchmark(tests[idx], iters);
jlaskey@3 178 }
jlaskey@3 179 }
jlaskey@3 180
jlaskey@3 181 var args = [];
lagergren@298 182
jlaskey@3 183 if (typeof $ARGS !== 'undefined') {
jlaskey@3 184 args = $ARGS;
jlaskey@3 185 } else if (typeof arguments !== 'undefined' && arguments.length != 0) {
jlaskey@3 186 args = arguments;
attila@962 187 }
jlaskey@3 188
jlaskey@3 189 var new_args = [];
jlaskey@3 190 for (i in args) {
jlaskey@3 191 if (args[i].toString().indexOf(' ') != -1) {
hannesw@1034 192 args[i] = args[i].replace(/\/$/, '');
hannesw@1034 193 var s = args[i].split(' ');
hannesw@1034 194 for (j in s) {
hannesw@1034 195 new_args.push(s[j]);
hannesw@1034 196 }
jlaskey@3 197 } else {
hannesw@1034 198 new_args.push(args[i]);
jlaskey@3 199 }
jlaskey@3 200 }
jlaskey@3 201
jlaskey@3 202 if (new_args.length != 0) {
jlaskey@3 203 args = new_args;
jlaskey@3 204 }
jlaskey@3 205
jlaskey@3 206 var tests_found = [];
jlaskey@3 207 var iters = undefined;
lagergren@295 208 var min_time = 5;
jlaskey@3 209
attila@962 210 for (var i = 0; i < args.length; i++) {
jlaskey@3 211 arg = args[i];
jlaskey@3 212 if (arg == "--iterations") {
hannesw@1034 213 iters = +args[++i];
hannesw@1034 214 if (isNaN(iters)) {
hannesw@1034 215 throw "'--iterations' must be followed by integer";
hannesw@1034 216 }
jlaskey@3 217 } else if (arg == "--runtime") {
hannesw@1034 218 runtime = args[++i];
jlaskey@3 219 } else if (arg == "--verbose") {
hannesw@1034 220 verbose = true;
lagergren@295 221 } else if (arg == "--min-time") {
hannesw@1034 222 min_time = +args[++i];
hannesw@1034 223 if (isNaN(iters)) {
hannesw@1034 224 throw "'--min-time' must be followed by integer";
hannesw@1034 225 }
jlaskey@3 226 } else if (arg == "") {
hannesw@1034 227 continue; //skip
jlaskey@3 228 } else {
hannesw@1034 229 var found = false;
hannesw@1034 230 for (j in tests) {
hannesw@1034 231 if (tests[j].name === arg) {
hannesw@1034 232 tests_found.push(tests[j]);
hannesw@1034 233 found = true;
hannesw@1034 234 break;
hannesw@1034 235 }
attila@962 236 }
hannesw@1034 237 if (!found) {
hannesw@1034 238 var str = "unknown test name: '" + arg + "' -- valid names are: ";
hannesw@1034 239 for (j in tests) {
hannesw@1034 240 if (j != 0) {
hannesw@1034 241 str += ", ";
hannesw@1034 242 }
hannesw@1034 243 str += "'" + tests[j].name + "'";
hannesw@1034 244 }
hannesw@1034 245 throw str;
attila@962 246 }
jlaskey@3 247 }
jlaskey@3 248 }
jlaskey@3 249
attila@962 250 if (tests_found.length == 0) {
jlaskey@3 251 for (i in tests) {
hannesw@1034 252 tests_found.push(tests[i]);
jlaskey@3 253 }
attila@962 254 }
jlaskey@3 255
attila@963 256 // returns false for rhino, v8 and all other javascript runtimes, true for Nashorn
attila@963 257 function is_this_nashorn() {
attila@963 258 return typeof Error.dumpStack == 'function'
attila@963 259 }
attila@963 260
attila@963 261 if (is_this_nashorn()) {
attila@963 262 try {
hannesw@1034 263 read = readFully;
attila@963 264 } catch (e) {
hannesw@1034 265 print("ABORTING: Cannot find 'readFully'. You must have scripting enabled to use this test harness. (-scripting)");
hannesw@1034 266 throw e;
attila@963 267 }
attila@963 268 }
attila@963 269
attila@963 270 // run tests in alphabetical order by name
attila@963 271 tests_found.sort(function(a, b) {
attila@963 272 if (a.name < b.name) {
hannesw@1034 273 return -1;
attila@963 274 } else if (a.name > b.name) {
hannesw@1034 275 return 1;
attila@963 276 } else {
hannesw@1034 277 return 0;
attila@963 278 }
attila@963 279 });
jlaskey@3 280
lagergren@295 281 load(path + 'base.js');
jlaskey@3 282 run_suite(tests_found, iters);

mercurial