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