Generator iteration - co vs bluebird

JavaScript performance comparison

Revision 2 of this test case created by Ramesh Nair

Preparation code

<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.0.min.js"></script>

<script>
  $(document).ready(function() {
    // thunk
    var setTimeoutPromise = function(ms) {
      return new Promise(function(resolve, reject){
        setTimeout(resolve, ms);
      });
    };


    window.generatorFunction = function*() {
      yield setTimeoutPromise(1);
      yield setTimeoutPromise(1);
    };

    window.module = {
      exports: null
    };

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

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

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


    $.getScript("https://raw.github.com/petkaantonov/bluebird/master/js/browser/bluebird.js", function() {
      $.getScript("https://raw.github.com/visionmedia/co/master/index.js", function() {
        window.co = window.module.exports;

        window.bluebirdPrepared = Promise.coroutine(generatorFunction);

        window.coPrepared = co(generatorFunction);

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

Preparation code output

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
Bluebird: Promise.spawn
// async test
runParallel(function(cb) {
  Promise.spawn(generatorFunction).then(cb);
}, function() {
  deferred.resolve();
});
pending…
co
// async test
runParallel(function(cb) {
  co(generatorFunction)(cb);
}, function() {
  deferred.resolve();
});
pending…
Bluebird: Promise.coroutine (prepared)
// async test
runParallel(function(cb) {
  bluebirdPrepared().then(cb);
}, function() {
  deferred.resolve();
});
pending…
co (prepared)
// async test
runParallel(function(cb) {
  coPrepared(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