Generator iteration - co vs bluebird (v6)

Revision 6 of this benchmark created by Timothy Gu on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.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