Generator iteration - co vs bluebird (v2)

Revision 2 of this benchmark created by Ramesh Nair on


Description

This tests the performance of the Promise.spawn against co.

Note: not all browsers support Generators. As of 14-Feb-2014 this test is known to run in Firefox Nightly

Preparation HTML

<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>

Test runner

Ready to run.

Testing in
TestOps/sec
Bluebird: Promise.spawn
// async test
runParallel(function(cb) {
  Promise.spawn(generatorFunction).then(cb);
}, function() {
  deferred.resolve();
});
 
ready
co
// async test
runParallel(function(cb) {
  co(generatorFunction)(cb);
}, function() {
  deferred.resolve();
});
 
ready
Bluebird: Promise.coroutine (prepared)
// async test
runParallel(function(cb) {
  bluebirdPrepared().then(cb);
}, function() {
  deferred.resolve();
});
 
ready
co (prepared)
// async test
runParallel(function(cb) {
  coPrepared(cb);
}, function() {
  deferred.resolve();
});
 
ready

Revisions

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

  • Revision 1: published by Ramesh Nair on
  • Revision 2: published by Ramesh Nair on
  • Revision 3: published on
  • Revision 4: published by Muscipular on
  • Revision 5: published on
  • Revision 6: published by Timothy Gu on