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

Side by Side Diff: chrome/test/data/third_party/spaceport/js/util/benchAsync.js

Issue 10134041: Add test data for spaceport benchmark. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months 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
OLDNEW
(Empty)
1 define([ 'util/ensureCallback' ], function (ensureCallback) {
2 // Benchmarks fn until maxTime ms has passed. Returns approximate number
3 // of operations performed in that time ('score').
4 function benchAsync(maxTime, fn, callback) {
5 if (typeof fn !== 'function') {
6 throw new TypeError('Argument must be a function');
7 }
8
9 var operationCount = 0;
10 var startTime;
11
12 function next() {
13 fn(operationCount, function () {
14 ++operationCount;
15
16 var endTime = Date.now();
17 if (endTime - startTime >= maxTime) {
18 var score = operationCount / (endTime - startTime) * maxTime ;
19 return callback(null, score);
20 } else {
21 return next();
22 }
23 });
24 }
25
26 setTimeout(function () {
27 startTime = Date.now();
28 next();
29 }, 0);
30 }
31
32 return benchAsync;
33 });
OLDNEW
« no previous file with comments | « chrome/test/data/third_party/spaceport/js/util/bench.js ('k') | chrome/test/data/third_party/spaceport/js/util/cacheBust.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698