promise comparisons

JavaScript performance comparison

Revision 28 of this test case created by Raymond

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.

Preparation code

<script src="//rawgithub.com/NobleJS/setImmediate/master/setImmediate.js">
</script>
<script src="//ajax.googleapis.com/ajax/libs/dojo/1/dojo/dojo.xd.js">
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/q.js/0.9.2/q.min.js">
</script>
<script src="//calvinmetcalf.github.io/promise-jsperf/javascripts/jQuery.js">
</script>
<script src="//medyk.org/deferred.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="//calvinmetcalf.github.io/promise-jsperf/javascripts/when.js">
</script>
<script src="//calvinmetcalf.github.io/promise-jsperf/javascripts/rsvp.js">
</script>
<script src="//calvinmetcalf.github.io/promise-jsperf/javascripts/promiscuous.js">
</script>
<script src="//rawgithub.com/JeanHuguesRobert/l8/master/lib/whisper.js">
</script>
<script>
  if (typeof(require) == 'undefined') {
    require = null;
  }
  exports = {};
</script>
<script src="//rawgithub.com/kriszyp/promised-io/master/promise.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
promiscuous
// async test
var d = promiscuous.deferred();
d.promise.then(function() {
  deferred.resolve()
})
d.resolve()
pending…
when
// async test
var d = when.defer()
d.promise.then(function() {
  deferred.resolve()
})
d.resolve()
pending…
jquery
// async test
var d = $.Deferred()
d.then(function() {
  deferred.resolve()
})
d.resolve()
pending…
RSVP
// async test
var d = RSVP.defer();
d.promise.then(function() {
  deferred.resolve()
})
d.resolve()
pending…
q
// async test
var d = Q.defer()
d.promise.then(function() {
  deferred.resolve()
})
d.resolve()
pending…
dojo
// async test
var d = new dojo.Deferred();
d.then(function() {
  deferred.resolve()
})
d.resolve();
pending…
deferred
// async test
var d = medikooDeferred();
d.promise.then(function() {
  deferred.resolve();
})
d.resolve();
pending…
Parole
// async test
var d = Parole();
d.then(function() {
  deferred.resolve();
});
d.resolve();
pending…
Promise/kriszyp
// async test
var d = exports.defer();
d.then(function() {
  deferred.resolve();
});
d.resolve();
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:

2 comments

Mariusz Nowak commented :

This tests are invalid, because jsPerf async handling is broken. See this -> https://github.com/mathiasbynens/jsperf.com/issues/128

In jsPerf using setImmediate is faster than sync execution -> http://jsperf.com/async-jsperf-test/2

Reason is that setImmediate runs faster than internal next turn mechanism forced by jsPerf in case of async test.

Q and When rely on setImmediate that's why they win deferred library doesn't defer execution of then, so it clearly should be faster than others that defer it, still it's shown as slower.

calvin commented :

That should be too big a problem here because promises MUST defer execution to be valid, so shouldn't have to worry about comparing apples to oranges (it also means deferred library shouldn't be here)

Add a comment