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