Generator iteration - co vs bluebird (v5)

Revision 5 of this benchmark created on


Preparation HTML

<script 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://cdnjs.cloudflare.com/ajax/libs/bluebird/2.7.1/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.coroutine (prepared)
// async test
runParallel(function(cb) {
  bluebirdPrepared().then(cb);
}, function() {
  deferred.resolve();
});
ready
co (prepared)
// async test
runParallel(function(cb) {
  coPrepared.then(cb,cb);
}, function() {
  deferred.resolve();
});
ready
Bluebird: Promise.spawn
// async test
runParallel(function(cb) {
  Promise.coroutine(generatorFunction)().then(cb);
}, function() {
  deferred.resolve();
});
ready
co
// async test
runParallel(function(cb) {
  co(generatorFunction).then(cb,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