promise comparisons

JavaScript performance comparison

Revision 46 of this test case created

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="https://rawgithub.com/calvinmetcalf/lie/mutation/dist/lie.noConflict.js"></script>
<script src="http://rsvpjs-builds.s3.amazonaws.com/rsvp-latest.js"></script>
<script src="//rawgithub.com/calvinmetcalf/catiline/gh-pages/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>
Benchmark.prototype.setup = function() {
     var channel = new MessageChannel();
};
</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 d = lie();
var code = 'lie' + Math.random();
function eventFunc(e) {
  if (e.data === code) {
window.removeEventListener('message',eventFunc);
    d.resolve();
}
}
window.addEventListener('message',eventFunc);
d.promise.then(function() {
  deferred.resolve()
})
window.postMessage(code, '*');
pending…
when
// async test
var d = when.defer()
var code = 'when' + Math.random();
function eventFunc(e) {
  if (e.data === code) {
window.removeEventListener('message',eventFunc);
    d.resolve();

}
}
window.addEventListener('message',eventFunc);
d.promise.then(function() {
  deferred.resolve()
})
window.postMessage(code, '*');
pending…
RSVP
// async test
var d = RSVP.defer();
var code = 'rsvp' + Math.random();
function eventFunc(e) {
  if (e.data === code) {
window.removeEventListener('message',eventFunc);
    d.resolve();

}
}
window.addEventListener('message',eventFunc);
d.promise.then(function() {
  deferred.resolve()
})
window.postMessage(code, '*');
pending…
q
// async test
var d = Q.defer()
var code = 'q' + Math.random();
function eventFunc(e) {
  if (e.data === code) {
window.removeEventListener('message',eventFunc);
    d.resolve();

}
}
window.addEventListener('message',eventFunc);
d.promise.then(function() {
  deferred.resolve()
})
window.postMessage(code, '*');
pending…
catiline
// async test
var d = cw.deferred()
var code = 'cw' + Math.random();
function eventFunc(e) {
  if (e.data === code) {
window.removeEventListener('message',eventFunc);
    d.resolve();

}
}
window.addEventListener('message',eventFunc);
d.promise.then(function() {
  deferred.resolve()
})
window.postMessage(code, '*');
pending…
message channel lie
// async test
var d = lie();
var code = 'lie' + Math.random();
function eventFunc(e) {
  if (e.data === code) {
    d.resolve();
}
}
channel.port1.onmessage=eventFunc;
d.promise.then(function() {
  deferred.resolve()
})
channel.port2.postMessage(code);
pending…
message channel when
// async test
var d = when.defer()
var code = 'when' + Math.random();
function eventFunc(e) {
  if (e.data === code) {
    d.resolve();
}
}
channel.port1.onmessage=eventFunc;
d.promise.then(function() {
  deferred.resolve()
})
channel.port2.postMessage(code);
pending…
message channel rsvp
// async test
var d = RSVP.defer();
var code = 'rsvp' + Math.random();
function eventFunc(e) {
  if (e.data === code) {
    d.resolve();
}
}
channel.port1.onmessage=eventFunc;
d.promise.then(function() {
  deferred.resolve()
})
channel.port2.postMessage(code);
pending…
message channel q
// async test
var d = Q.defer()
var code = 'q' + Math.random();
function eventFunc(e) {
  if (e.data === code) {
    d.resolve();
}
}
channel.port1.onmessage=eventFunc;
d.promise.then(function() {
  deferred.resolve()
})
channel.port2.postMessage(code);
pending…
message channel catline
// async test
var d = cw.deferred()
var code = 'cw' + Math.random();
function eventFunc(e) {
  if (e.data === code) {
    d.resolve();
}
}
channel.port1.onmessage=eventFunc;
d.promise.then(function() {
  deferred.resolve()
})
channel.port2.postMessage(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