Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

The implementation of "minimum runtime" is inaccurate #3

Open
lmnbeyond opened this issue Aug 14, 2013 · 0 comments
Open

The implementation of "minimum runtime" is inaccurate #3

lmnbeyond opened this issue Aug 14, 2013 · 0 comments

Comments

@lmnbeyond
Copy link

@akdubya

According to README.md:

var suite = new uubench.Suite({
  min: 1000, // each benchmark should run for at least 1000ms
  ...
 });

I looked up the source code:

function adaptive() {
    if (--pend === 0) {
      var elapsed = new Date() - start;
      if (elapsed < min) {
        self.run(iter*2);
      } else {
        self.callback({iterations: iter, elapsed: elapsed});//since "start" is reset whenever "Bench.run" is invoked, then the stats is inaccurate
      }
    }
  }

The key point is that the value of "start" is reset whenever "Bench.run" is invoked:

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;

  if (self.loop) {
    pend = 1;
    start = new Date();  //start is reset
    fn(checkfn, i);
  } else {
    start = new Date();   //start is reset
    while (i--) {
      fn(checkfn);
    }
  }

So the stats is inaccurate, I think the value of "start" should be set at the very begining of "Suite.prototype.runOne", and don't reset it in Bench.run:

Suite.prototype.runOne = function(idx) {
  var self = this;
  setTimeout(function() {
    self.tests[idx].start = new Date().getTime();  //set "start" value here, so "min" is the accumulative runtime for benchmark
    self.tests[idx].run(self.options.iterations);
  }, self.options.delay);
}

I'm very curious to this issue. Please give me a hint!

Finally, many thanks to you for your great work and the sharing :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant