Generator iteration - co vs bluebird

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 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);
      yield setTimeoutPromise(1);
      yield setTimeoutPromise(1);
    };

    window.module = {
      exports: null
    };

    $.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;
      });
    });
  });
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Bluebird: Promise.spawn
// async test
Promise.spawn(window.generatorFunction).then(function() {
  deferred.resolve();
});
 
ready
co
// async test
co(window.generatorFunction)(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