promise comparisons

JavaScript performance comparison

Revision 75 of this test case created by GotDibbs

Info

This is a comparison of different promise libraries, performing the most basic tasks of creating a promise, adding a then handler and then resolving the promise.

Recent benchmarks deliberately cripple bluebird but didn't force the same method on other libraries.

*Added JQuery

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="https://rawgithub.com/cho45/jsdeferred/master/jsdeferred.js"></script>
<script src="https://rawgithub.com/petkaantonov/bluebird/master/js/browser/bluebird.js">
</script>
<script>
  window.BluebirdPromise = window.Promise.noConflict();
</script>
<script src="https://rawgithub.com/calvinmetcalf/lie/master/dist/lie.noConflict.js"></script><script src="http://rsvpjs-builds.s3.amazonaws.com/rsvp-latest.js"></script>
<script src="//rawgithub.com/calvinmetcalf/catiline/master/dist/catiline.js"></script>

<script src="//cdnjs.cloudflare.com/ajax/libs/q.js/0.9.6/q.min.js">
</script>
<script>
  window.define = function(factory) {
    try {
      delete window.define;
    } catch (e) {
      window.define = void 0;
    } // IE
    window.when = factory();
  };
  window.define.amd = {};
</script>
<script src="https://rawgithub.com/cujojs/when/master/when.js"></script><script>
var worker = cw({
    init:function(self){
        self.on('ping',function(d){
            self.fire('pong',d);
        });
}
    });
</script>
<script src="http://yui.yahooapis.com/3.12.0/build/yui/yui-min.js"></script>
<script>
YUI().use('promise', function (Y) {
    window.Y = Y;
});
</script>
<script src="http://rawgithub.com/dfilatov/jspromise/master/vow.min.js"></script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
lie
// async test
var eventFunc;
var code = 'lie' + Math.random();
var d = lie(function(resolve) {

  eventFunc = function(e) {
    if (e === code) {
      worker.off('pong');
      resolve();
    }
  }
});
worker.on('pong', eventFunc);
d.then(function() {
  deferred.resolve()
});
worker.fire('ping', code);
pending…
when
// async test
var code = 'when' + Math.random();
var promise = when.promise(function(resolve) {
  function eventFunc(e) {
    if (e === code) {
      worker.off('pong');
      resolve();
    }
  }
  worker.on('pong', eventFunc);
});

promise.then(function() {
  deferred.resolve();
})
worker.fire('ping', code);
pending…
RSVP
// async test
var d = RSVP.defer();
var code = 'rsvp' + Math.random();

function eventFunc(e) {
  if (e === code) {
    worker.off('pong');
    d.resolve();
  }
}
worker.on('pong', eventFunc);
d.promise.then(function() {
  deferred.resolve();
})
worker.fire('ping', code);
pending…
q
// async test
var d = Q.defer()
var code = 'q' + Math.random();

function eventFunc(e) {
  if (e === code) {
    worker.off('pong');
    d.resolve();
  }
}
worker.on('pong', eventFunc);
d.promise.then(function() {
  deferred.resolve();
})
worker.fire('ping', code);
pending…
catiline
// async test
var d = cw.deferred()
var code = 'cw' + Math.random();

function eventFunc(e) {
  if (e === code) {
    worker.off('pong');
    d.resolve();
  }
}
worker.on('pong', eventFunc);
d.promise.then(function() {
  deferred.resolve();
})
worker.fire('ping', code);
pending…
bluebird
// async test
var eventFunc;
var code = 'bluebird' + Math.random();
var d = BluebirdPromise.pending()


  eventFunc = function(e) {
    if (e === code) {
      worker.off('pong');
      d.fulfill();
    }
  };

worker.on('pong', eventFunc);
d.promise.then(function() {
  deferred.resolve();
});
worker.fire('ping', code);
pending…
promhx
return;
pending…
yui
// async test
var eventFunc;
var code = 'yui' + Math.random();
var d = new Y.Promise(function(resolve) {

  eventFunc = function(e) {
    if (e === code) {
      worker.off('pong');
      resolve();
    }
  }
});
worker.on('pong', eventFunc);
d.then(function() {
  deferred.resolve();
});
worker.fire('ping', code);
pending…
JQuery
// async test
var eventFunc;
var code = 'jquery' + Math.random();
var d = new jQuery.Deferred();


eventFunc = function(e) {
  if (e === code) {
    worker.off('pong');
    d.resolve();
  }
}

worker.on('pong', eventFunc);
d.then(function() {
  deferred.resolve();
});
worker.fire('ping', code);
pending…
Vow
// async test
var eventFunc;
var code = 'vow' + Math.random();
var d = Vow.promise();

eventFunc = function(e) {
  if (e === code) {
    worker.off('pong');
    d.fulfill();
  }
}

worker.on('pong', eventFunc);
d.then(function() {
  deferred.resolve();
});
worker.fire('ping', code);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment