test/script/basic/run-octane.js

changeset 962
ac62e33a99b0
parent 693
18edd7a1b166
child 963
e2497b11a021
equal deleted inserted replaced
961:93b032dd26bc 962:ac62e33a99b0
1 /* 1 /*
2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 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. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT 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 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 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 12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code). 13 * accompanied this code).
14 * 14 *
15 * You should have received a copy of the GNU General Public License version 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, 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. 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 * 18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 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 20 * or visit www.oracle.com if you need additional information or have any
21 * questions. 21 * questions.
22 */ 22 */
23 23
62 } 62 }
63 63
64 function load_bench(arg) { 64 function load_bench(arg) {
65 65
66 for (var idx = 0; idx < arg.files.length; idx++) { 66 for (var idx = 0; idx < arg.files.length; idx++) {
67 var f = arg.files[idx]; 67 var f = arg.files[idx];
68 var file = f.split('/'); 68 var file = f.split('/');
69 var file_name = path + file[file.length - 1]; 69 var file_name = path + file[file.length - 1];
70 70
71 var compile_and_return = should_compile_only(file_name); 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) { 72 if (compile_and_return) {
83 print_always(arg, "Compiled OK"); 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 } 84 }
85 return !compile_and_return; 85 return !compile_and_return;
86 86
87 } 87 }
88 88
89 function run_one_benchmark(arg, iters) { 89 function run_one_benchmark(arg, iters) {
90 90
91 if (!load_bench(arg)) { 91 if (!load_bench(arg)) {
92 return; 92 return;
93 } 93 }
94 94
95 var success = true; 95 var success = true;
96 var current_name; 96 var current_name;
97 97
98 if (iters == undefined) { 98 if (iters == undefined) {
99 iters = numberOfIterations; 99 iters = numberOfIterations;
100 } else { 100 } else {
101 numberOfIterations = iters; 101 numberOfIterations = iters;
102 } 102 }
103 103
104 var benchmarks = eval(arg.suite + ".benchmarks"); 104 var benchmarks = eval(arg.suite + ".benchmarks");
105 var min_score = 1e9; 105 var min_score = 1e9;
106 var max_score = 0; 106 var max_score = 0;
107 var mean_score = 0; 107 var mean_score = 0;
108 108
109 try { 109 try {
110 for (var x = 0; x < benchmarks.length ; x++) { 110 for (var x = 0; x < benchmarks.length ; x++) {
111 //do warmup run 111 //do warmup run
112 //reset random number generator needed as of octane 9 before each run 112 //reset random number generator needed as of octane 9 before each run
113 BenchmarkSuite.ResetRNG(); 113 BenchmarkSuite.ResetRNG();
114 benchmarks[x].Setup(); 114 benchmarks[x].Setup();
115 } 115 }
116 BenchmarkSuite.ResetRNG(); 116 BenchmarkSuite.ResetRNG();
117 print_verbose(arg, "running '" + arg.name + "' for " + iters + " iterations of no less than " + min_time + " seconds (" + runtime + ")"); 117 print_verbose(arg, "running '" + arg.name + "' for " + iters + " iterations of no less than " + min_time + " seconds (" + runtime + ")");
118 118
119 var scores = []; 119 var scores = [];
120 120
121 var min_time_ms = min_time * 1000; 121 var min_time_ms = min_time * 1000;
122 var len = benchmarks.length; 122 var len = benchmarks.length;
123 123
124 for (var it = 0; it < iters + 1; it++) { 124 for (var it = 0; it < iters + 1; it++) {
125 //every iteration must take a minimum of 10 secs 125 //every iteration must take a minimum of 10 secs
126 var ops = 0; 126 var ops = 0;
127 var elapsed = 0; 127 var elapsed = 0;
128 var start = new Date; 128 var start = new Date;
129 do { 129 do {
130 for (var i = 0; i < len; i++) { 130 for (var i = 0; i < len; i++) {
131 benchmarks[i].run(); 131 benchmarks[i].run();
132 //important - no timing here like elapsed = new Date() - start, as in the 132 //important - no timing here like elapsed = new Date() - start, as in the
133 //original harness. This will make timing very non-deterministic. 133 //original harness. This will make timing very non-deterministic.
134 //NOTHING else must live in this loop 134 //NOTHING else must live in this loop
135 } 135 }
136 ops += len; 136 ops += len;
137 elapsed = new Date - start; 137 elapsed = new Date - start;
138 } while (elapsed < min_time * 1000); 138 } while (elapsed < min_time * 1000);
139 139
140 var score = ops / elapsed * 1000 * 60; 140 var score = ops / elapsed * 1000 * 60;
141 scores.push(score); 141 scores.push(score);
142 var name = it == 0 ? "warmup" : "iteration " + it; 142 var name = it == 0 ? "warmup" : "iteration " + it;
143 print_verbose(arg, name + " finished " + score.toFixed(0) + " ops/minute"); 143 print_verbose(arg, name + " finished " + score.toFixed(0) + " ops/minute");
144 } 144 }
145 145
146 for (var x = 0; x < benchmarks.length ; x++) { 146 for (var x = 0; x < benchmarks.length ; x++) {
147 benchmarks[x].TearDown(); 147 benchmarks[x].TearDown();
148 } 148 }
149 149
150 for (var x = 1; x < iters + 1 ; x++) { 150 for (var x = 1; x < iters + 1 ; x++) {
151 mean_score += scores[x]; 151 mean_score += scores[x];
152 min_score = Math.min(min_score, scores[x]); 152 min_score = Math.min(min_score, scores[x]);
153 max_score = Math.max(max_score, scores[x]); 153 max_score = Math.max(max_score, scores[x]);
154 } 154 }
155 mean_score /= iters; 155 mean_score /= iters;
156 156
157 } catch (e) { 157 } catch (e) {
158 print_always("*** Aborted and setting score to zero. Reason: " + e); 158 print_always("*** Aborted and setting score to zero. Reason: " + e);
159 mean_score = min_score = max_score = 0; 159 mean_score = min_score = max_score = 0;
160 scores = [0]; 160 scores = [0];
161 } 161 }
162 162
163 var res = mean_score.toFixed(0); 163 var res = mean_score.toFixed(0);
164 if (verbose) { 164 if (verbose) {
165 res += " ops/minute (" + min_score.toFixed(0) + "-" + max_score.toFixed(0) + "), warmup=" + scores[0].toFixed(0); 165 res += " ops/minute (" + min_score.toFixed(0) + "-" + max_score.toFixed(0) + "), warmup=" + scores[0].toFixed(0);
166 } 166 }
167 print_always(arg, res); 167 print_always(arg, res);
168 } 168 }
169 169
170 function print_always(arg, x) { 170 function print_always(arg, x) {
171 print("[" + arg.name + "] " + x); 171 print("[" + arg.name + "] " + x);
172 } 172 }
173 173
174 function print_verbose(arg, x) { 174 function print_verbose(arg, x) {
175 if (verbose) { 175 if (verbose) {
176 print_always(arg, x) 176 print_always(arg, x)
177 } 177 }
178 } 178 }
179 179
180 function run_suite(tests, iters) { 180 function run_suite(tests, iters) {
181 for (var idx = 0; idx < tests.length; idx++) { 181 for (var idx = 0; idx < tests.length; idx++) {
182 run_one_benchmark(tests[idx], iters); 182 run_one_benchmark(tests[idx], iters);
183 } 183 }
184 } 184 }
185 185
186 runtime = "command line"; 186 runtime = "command line";
187 187
189 189
190 if (typeof $ARGS !== 'undefined') { 190 if (typeof $ARGS !== 'undefined') {
191 args = $ARGS; 191 args = $ARGS;
192 } else if (typeof arguments !== 'undefined' && arguments.length != 0) { 192 } else if (typeof arguments !== 'undefined' && arguments.length != 0) {
193 args = arguments; 193 args = arguments;
194 } 194 }
195 195
196 var new_args = []; 196 var new_args = [];
197 for (i in args) { 197 for (i in args) {
198 if (args[i].toString().indexOf(' ') != -1) { 198 if (args[i].toString().indexOf(' ') != -1) {
199 args[i] = args[i].replace(/\/$/, ''); 199 args[i] = args[i].replace(/\/$/, '');
200 var s = args[i].split(' '); 200 var s = args[i].split(' ');
201 for (j in s) { 201 for (j in s) {
202 new_args.push(s[j]); 202 new_args.push(s[j]);
203 } 203 }
204 } else { 204 } else {
205 new_args.push(args[i]); 205 new_args.push(args[i]);
206 } 206 }
207 } 207 }
208 208
209 if (new_args.length != 0) { 209 if (new_args.length != 0) {
210 args = new_args; 210 args = new_args;
212 212
213 var tests_found = []; 213 var tests_found = [];
214 var iters = undefined; 214 var iters = undefined;
215 var min_time = 5; 215 var min_time = 5;
216 216
217 for (var i = 0; i < args.length; i++) { 217 for (var i = 0; i < args.length; i++) {
218 arg = args[i]; 218 arg = args[i];
219 if (arg == "--iterations") { 219 if (arg == "--iterations") {
220 iters = +args[++i]; 220 iters = +args[++i];
221 } else if (arg == "--runtime") { 221 } else if (arg == "--runtime") {
222 runtime = args[++i]; 222 runtime = args[++i];
223 } else if (arg == "--verbose") { 223 } else if (arg == "--verbose") {
224 verbose = true; 224 verbose = true;
225 } else if (arg == "--min-time") { 225 } else if (arg == "--min-time") {
226 min_time = +args[++i]; 226 min_time = +args[++i];
227 } else if (arg == "") { 227 } else if (arg == "") {
228 continue; //skip 228 continue; //skip
229 } else { 229 } else {
230 var found = false; 230 var found = false;
231 for (j in tests) { 231 for (j in tests) {
232 if (tests[j].name === arg) { 232 if (tests[j].name === arg) {
233 tests_found.push(tests[j]); 233 tests_found.push(tests[j]);
234 found = true; 234 found = true;
235 break; 235 break;
236 } 236 }
237 } 237 }
238 if (!found) { 238 if (!found) {
239 var str = "unknown test name: '" + arg + "' -- valid names are: "; 239 var str = "unknown test name: '" + arg + "' -- valid names are: ";
240 for (j in tests) { 240 for (j in tests) {
241 if (j != 0) { 241 if (j != 0) {
242 str += ", "; 242 str += ", ";
243 } 243 }
244 str += "'" + tests[j].name + "'"; 244 str += "'" + tests[j].name + "'";
245 } 245 }
246 throw str; 246 throw str;
247 } 247 }
248 } 248 }
249 } 249 }
250 250
251 if (tests_found.length == 0) { 251 if (tests_found.length == 0) {
252 for (i in tests) { 252 for (i in tests) {
253 tests_found.push(tests[i]); 253 tests_found.push(tests[i]);
254 } 254 }
255 } 255 }
256 256
257 tests_found.sort(); 257 tests_found.sort();
258 258
259 load(path + 'base.js'); 259 load(path + 'base.js');
260 run_suite(tests_found, iters); 260 run_suite(tests_found, iters);

mercurial