promise comparisons

JavaScript performance comparison

Revision 19 of this test case created by Meryn Stol

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.

Removed SLOW laissez-faire Removed avow which has bad code for checking module

Resolve immediately, without any kind of timeout or delay. Don't include setImmediate shim to see how the libs fair on their own.

Preparation code

<script src="http://mstade.github.com/promise-jsperf/javascripts/q.js"></script>
<script src="https://raw.github.com/dfilatov/jspromise/master/vow.min.js"></script>
<script src="//code.jquery.com/jquery-2.0.0.min.js"></script>
<script src="http://olostan.org.ua/libs/when.js"></script>
<script src="https://raw.github.com/tildeio/rsvp.js/rsvp2/browser/rsvp.min.js"></script>
<script src="https://raw.github.com/gameclosure/ff/master/lib/ff.js"></script>

<script src="https://raw.github.com/caolan/async/master/lib/async.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
when
// async test
var work = function() {
  var d = when.defer()
  d.resolve()
  return d.promise;
}

work().then(function() {
  deferred.resolve();
});
pending…
q
// async test
var work = function() {
  var d = Q.defer();
  d.resolve()
  return d.promise;
};

work().then(function() {
  deferred.resolve();
});
pending…
jquery
// async test
var work = function() {
  var d = $.Deferred()
  d.resolve()
  return d;
};

work().then(function() {
  deferred.resolve();
});
pending…
Vow - jspromise
// async test
var work = function() {
  var vow = Vow.promise();
  vow.fulfill()
  return vow;
};

work().then(function() {
  deferred.resolve();
});
pending…
ff
// async test
var work = function() {
  var f = ff.defer();
  f()
  return f;
};

work().then(function() {
  deferred.resolve();
});
pending…
rsvp
// async test
var work = function() {
  var rs = new RSVP.Promise(function(resolve, reject) {
    resolve()
  });
  return rs;  
};

work().then(function() {
  deferred.resolve();
});
pending…
async
// async test
var work = function(cb) {
  cb();
};
async.series([work], function() {
  deferred.resolve();
});
pending…
callback
// async test
var work = function(cb) {
  cb();
};

work(function() {
  deferred.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:

0 comments

Add a comment