Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: chrome/test/data/v8_benchmark/base.js

Issue 8749001: Upgrade V8 Benchmark from v4 to v6. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/data/v8_benchmark/README.txt ('k') | chrome/test/data/v8_benchmark/crypto.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 71 }
72 72
73 73
74 // Keep track of all declared benchmark suites. 74 // Keep track of all declared benchmark suites.
75 BenchmarkSuite.suites = []; 75 BenchmarkSuite.suites = [];
76 76
77 77
78 // Scores are not comparable across versions. Bump the version if 78 // Scores are not comparable across versions. Bump the version if
79 // you're making changes that will affect that scores, e.g. if you add 79 // you're making changes that will affect that scores, e.g. if you add
80 // a new benchmark or change an existing one. 80 // a new benchmark or change an existing one.
81 BenchmarkSuite.version = '4'; 81 BenchmarkSuite.version = '6';
82 82
83 83
84 // To make the benchmark results predictable, we replace Math.random 84 // To make the benchmark results predictable, we replace Math.random
85 // with a 100% deterministic alternative. 85 // with a 100% deterministic alternative.
86 Math.random = (function() { 86 Math.random = (function() {
87 var seed = 49734321; 87 var seed = 49734321;
88 return function() { 88 return function() {
89 // Robert Jenkins' 32 bit integer hash function. 89 // Robert Jenkins' 32 bit integer hash function.
90 seed = ((seed + 0x7ed55d16) + (seed << 12)) & 0xffffffff; 90 seed = ((seed + 0x7ed55d16) + (seed << 12)) & 0xffffffff;
91 seed = ((seed ^ 0xc761c23c) ^ (seed >>> 19)) & 0xffffffff; 91 seed = ((seed ^ 0xc761c23c) ^ (seed >>> 19)) & 0xffffffff;
92 seed = ((seed + 0x165667b1) + (seed << 5)) & 0xffffffff; 92 seed = ((seed + 0x165667b1) + (seed << 5)) & 0xffffffff;
93 seed = ((seed + 0xd3a2646c) ^ (seed << 9)) & 0xffffffff; 93 seed = ((seed + 0xd3a2646c) ^ (seed << 9)) & 0xffffffff;
94 seed = ((seed + 0xd3a2646c) ^ (seed << 9)) & 0xffffffff;
95 seed = ((seed + 0xfd7046c5) + (seed << 3)) & 0xffffffff; 94 seed = ((seed + 0xfd7046c5) + (seed << 3)) & 0xffffffff;
96 seed = ((seed ^ 0xb55a4f09) ^ (seed >>> 16)) & 0xffffffff; 95 seed = ((seed ^ 0xb55a4f09) ^ (seed >>> 16)) & 0xffffffff;
97 return (seed & 0xfffffff) / 0x10000000; 96 return (seed & 0xfffffff) / 0x10000000;
98 }; 97 };
99 })(); 98 })();
100 99
101 100
102 // Runs all registered benchmark suites and optionally yields between 101 // Runs all registered benchmark suites and optionally yields between
103 // each individual benchmark to avoid running for too long in the 102 // each individual benchmark to avoid running for too long in the
104 // context of browsers. Once done, the final score is reported to the 103 // context of browsers. Once done, the final score is reported to the
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 this.runner.NotifyError(this.name, error); 191 this.runner.NotifyError(this.name, error);
193 } 192 }
194 if (this.runner.NotifyStep) { 193 if (this.runner.NotifyStep) {
195 this.runner.NotifyStep(this.name); 194 this.runner.NotifyStep(this.name);
196 } 195 }
197 } 196 }
198 197
199 198
200 // Runs a single benchmark for at least a second and computes the 199 // Runs a single benchmark for at least a second and computes the
201 // average time it takes to run a single iteration. 200 // average time it takes to run a single iteration.
202 BenchmarkSuite.prototype.RunSingleBenchmark = function(benchmark) { 201 BenchmarkSuite.prototype.RunSingleBenchmark = function(benchmark, data) {
203 var elapsed = 0; 202 function Measure(data) {
204 var start = new Date(); 203 var elapsed = 0;
205 for (var n = 0; elapsed < 1000; n++) { 204 var start = new Date();
206 benchmark.run(); 205 for (var n = 0; elapsed < 1000; n++) {
207 elapsed = new Date() - start; 206 benchmark.run();
207 elapsed = new Date() - start;
208 }
209 if (data != null) {
210 data.runs += n;
211 data.elapsed += elapsed;
212 }
208 } 213 }
209 var usec = (elapsed * 1000) / n; 214
210 this.NotifyStep(new BenchmarkResult(benchmark, usec)); 215 if (data == null) {
216 // Measure the benchmark once for warm up and throw the result
217 // away. Return a fresh data object.
218 Measure(null);
219 return { runs: 0, elapsed: 0 };
220 } else {
221 Measure(data);
222 // If we've run too few iterations, we continue for another second.
223 if (data.runs < 32) return data;
224 var usec = (data.elapsed * 1000) / data.runs;
225 this.NotifyStep(new BenchmarkResult(benchmark, usec));
226 return null;
227 }
211 } 228 }
212 229
213 230
214 // This function starts running a suite, but stops between each 231 // This function starts running a suite, but stops between each
215 // individual benchmark in the suite and returns a continuation 232 // individual benchmark in the suite and returns a continuation
216 // function which can be invoked to run the next benchmark. Once the 233 // function which can be invoked to run the next benchmark. Once the
217 // last benchmark has been executed, null is returned. 234 // last benchmark has been executed, null is returned.
218 BenchmarkSuite.prototype.RunStep = function(runner) { 235 BenchmarkSuite.prototype.RunStep = function(runner) {
219 this.results = []; 236 this.results = [];
220 this.runner = runner; 237 this.runner = runner;
221 var length = this.benchmarks.length; 238 var length = this.benchmarks.length;
222 var index = 0; 239 var index = 0;
223 var suite = this; 240 var suite = this;
241 var data;
224 242
225 // Run the setup, the actual benchmark, and the tear down in three 243 // Run the setup, the actual benchmark, and the tear down in three
226 // separate steps to allow the framework to yield between any of the 244 // separate steps to allow the framework to yield between any of the
227 // steps. 245 // steps.
228 246
229 function RunNextSetup() { 247 function RunNextSetup() {
230 if (index < length) { 248 if (index < length) {
231 try { 249 try {
232 suite.benchmarks[index].Setup(); 250 suite.benchmarks[index].Setup();
233 } catch (e) { 251 } catch (e) {
234 suite.NotifyError(e); 252 suite.NotifyError(e);
235 return null; 253 return null;
236 } 254 }
237 return RunNextBenchmark; 255 return RunNextBenchmark;
238 } 256 }
239 suite.NotifyResult(); 257 suite.NotifyResult();
240 return null; 258 return null;
241 } 259 }
242 260
243 function RunNextBenchmark() { 261 function RunNextBenchmark() {
244 try { 262 try {
245 suite.RunSingleBenchmark(suite.benchmarks[index]); 263 data = suite.RunSingleBenchmark(suite.benchmarks[index], data);
246 } catch (e) { 264 } catch (e) {
247 suite.NotifyError(e); 265 suite.NotifyError(e);
248 return null; 266 return null;
249 } 267 }
250 return RunNextTearDown; 268 // If data is null, we're done with this benchmark.
269 return (data == null) ? RunNextTearDown : RunNextBenchmark();
251 } 270 }
252 271
253 function RunNextTearDown() { 272 function RunNextTearDown() {
254 try { 273 try {
255 suite.benchmarks[index++].TearDown(); 274 suite.benchmarks[index++].TearDown();
256 } catch (e) { 275 } catch (e) {
257 suite.NotifyError(e); 276 suite.NotifyError(e);
258 return null; 277 return null;
259 } 278 }
260 return RunNextSetup; 279 return RunNextSetup;
261 } 280 }
262 281
263 // Start out running the setup. 282 // Start out running the setup.
264 return RunNextSetup(); 283 return RunNextSetup();
265 } 284 }
OLDNEW
« no previous file with comments | « chrome/test/data/v8_benchmark/README.txt ('k') | chrome/test/data/v8_benchmark/crypto.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698