test/script/basic/run-octane.js

Wed, 27 Apr 2016 01:36:41 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:36:41 +0800
changeset 0
b1a7da25b547
child 952
6d5471a497fb
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/nashorn/
changeset: 1034:4b9cc65dd24d
tag: jdk8u25-b17

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

mercurial