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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/third_party/spaceport/js/util/benchAsync.js
diff --git a/chrome/test/data/third_party/spaceport/js/util/benchAsync.js b/chrome/test/data/third_party/spaceport/js/util/benchAsync.js
new file mode 100644
index 0000000000000000000000000000000000000000..799b635caff4fbcb2551656646a431b31b3d4036
--- /dev/null
+++ b/chrome/test/data/third_party/spaceport/js/util/benchAsync.js
@@ -0,0 +1,33 @@
+define([ 'util/ensureCallback' ], function (ensureCallback) {
+ // Benchmarks fn until maxTime ms has passed. Returns approximate number
+ // of operations performed in that time ('score').
+ function benchAsync(maxTime, fn, callback) {
+ if (typeof fn !== 'function') {
+ throw new TypeError('Argument must be a function');
+ }
+
+ var operationCount = 0;
+ var startTime;
+
+ function next() {
+ fn(operationCount, function () {
+ ++operationCount;
+
+ var endTime = Date.now();
+ if (endTime - startTime >= maxTime) {
+ var score = operationCount / (endTime - startTime) * maxTime;
+ return callback(null, score);
+ } else {
+ return next();
+ }
+ });
+ }
+
+ setTimeout(function () {
+ startTime = Date.now();
+ next();
+ }, 0);
+ }
+
+ return benchAsync;
+});
« 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