From 402418c2e02a578fb3b9de6fcd70651a11e1aff6 Mon Sep 17 00:00:00 2001 From: lmnbeyond Date: Wed, 14 Aug 2013 18:24:35 +0800 Subject: [PATCH] Adjust the value of start For more information, please refer to https://github.com/akdubya/uubench/issues/3 --- uubench.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/uubench.js b/uubench.js index 7337165..a1e0edd 100644 --- a/uubench.js +++ b/uubench.js @@ -20,14 +20,12 @@ Bench.prototype.run = function(iter) { var self = this, fn = self.test, checkfn = self.options.type === "adaptive" ? adaptive : fixed, i = iter, pend = i, - min = self.options.min, start; + min = self.options.min, start = self.start; if (self.loop) { pend = 1; - start = new Date(); fn(checkfn, i); } else { - start = new Date(); while (i--) { fn(checkfn); } @@ -35,14 +33,14 @@ Bench.prototype.run = function(iter) { function fixed() { if (--pend === 0) { - var elapsed = new Date() - start; + var elapsed = new Date().getTime() - start; self.callback({iterations: iter, elapsed: elapsed}); } } function adaptive() { if (--pend === 0) { - var elapsed = new Date() - start; + var elapsed = new Date().getTime() - start; if (elapsed < min) { self.run(iter*2); } else { @@ -94,6 +92,7 @@ Suite.prototype.run = function() { Suite.prototype.runOne = function(idx) { var self = this; setTimeout(function() { + self.tests[idx].start = new Date().getTime(); self.tests[idx].run(self.options.iterations); }, self.options.delay); } @@ -112,4 +111,4 @@ Suite.prototype.emit = function(type) { uubench.Suite = Suite; -})(typeof exports !== 'undefined' ? exports : window.uubench = {}); \ No newline at end of file +})(typeof exports !== 'undefined' ? exports : window.uubench = {});