Generator delegation

JavaScript performance comparison

Revision 3 of this test case created by Ramesh Nair

Preparation code

<script>
var tools = window.tools = {};

// thunk
tools.setTimeoutThunk = function(ms) {
  return function(cb) {
    setTimeout(cb, ms);
  };
};

tools.delegated = function*() {
  yield tools.setTimeoutThunk(1);
  yield tools.setTimeoutThunk(1);
};

tools.delegator = function*() {
  yield* tools.delegated();
};

tools.runParallel = function(fn, cb) {
  var yetToReturn = numCallsToMake = 10000;

  var fnCb = function() {
    if (0 === --yetToReturn) cb();
  };

  while (0 < numCallsToMake--) {
    fn(fnCb);
  }
};

console.log('Tools setup!');
</script>
    

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Without delegation
// async test
tools.runParallel(function(cb) {
  var gen = tools.delegated(),
    done = false;

  while (!done) {
    done = gen.next().done;
  }

  cb();
}, function() {
  deferred.resolve();
});
pending…
With delegation
// async test
tools.runParallel(function(cb) {
  var gen = tools.delegator(),
    done = false;

  while (!done) {
    done = gen.next().done;
  }

  cb();
}, function() {
  deferred.resolve();
});
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments