Generator iteration - co vs bluebird (v3)

Revision 3 of this benchmark created 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 src="http://code.jquery.com/jquery-2.1.0.min.js"></script>

<script type="text/javascript">
  $(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://rawgit.com/petkaantonov/bluebird/master/js/browser/bluebird.js", function() {
      $.getScript("https://rawgit.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