Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Adjust the value of start #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions uubench.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,27 @@ 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);
}
}

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 {
Expand Down Expand Up @@ -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);
}
Expand All @@ -112,4 +111,4 @@ Suite.prototype.emit = function(type) {

uubench.Suite = Suite;

})(typeof exports !== 'undefined' ? exports : window.uubench = {});
})(typeof exports !== 'undefined' ? exports : window.uubench = {});