promise comparisons

JavaScript performance comparison

Revision 142 of this test case created by Billy Tetrud

Preparation code

<script>
  // pimp installs a global setImmediate shim
  var _setImmediate = window.setImmediate;
  var _Promise = window.Promise;
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/dfilatov/vow/0.4.7/vow.min.js"></script>
<script src="https://cdn.rawgit.com/petkaantonov/bluebird/v2.3.11/js/browser/bluebird.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/q.js/1.1.1/q.min.js"></script>
<script src="https://rsvpjs-builds.s3.amazonaws.com/rsvp-latest.js"></script>
<script src="https://cdn.rawgit.com/calvinmetcalf/lie/2.7.7/dist/lie.noConflict.js"></script>
<script src="https://cdn.rawgit.com/calvinmetcalf/catiline/2.9.3/dist/catiline.js"></script>
//kew 0.5.0-alpha1
<script src="http://pastebin.com/raw.php?i=b7R6bgzk"></script>
<script src="https://cdn.rawgit.com/zeusdeux/pimp/0.2.3/browser/pimp.0.2.3.js"></script>
<script src="http://mstade.github.com/promise-jsperf/javascripts/when.js"></script>
<script src="http://www.btetrud.com/files/asyncFuture.umd.js"></script>
<script>
  window.setImmediate = _setImmediate;
  window.Promise = _Promise;
</script>
    

Preparation code output

//kew 0.5.0-alpha1

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
lie
// async test
var code = 'lie' + Math.random();
var p = new Lie(function(resolve, reject) {
  function eventFunc(e) {
    if (e.data === code) {
      window.removeEventListener('message', eventFunc);
      resolve();
    }
  }
  window.addEventListener('message', eventFunc);
});

p.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…
bluebird
// async test
var d = P.pending();
var code = 'pend' + Math.random();

function eventFunc(e) {
  if (e.data === code) {
    window.removeEventListener('message', eventFunc);
    d.fulfill();

  }
}

d.promise.then(function() {
  deferred.resolve()
});
window.addEventListener('message', eventFunc);
window.postMessage(code, '*');
pending…
Pimp
// async test
var d = Pimp.deferred()
var code = 'pimp' + 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…
vow
// async test
var d = vow.defer();
var code = 'nat' + 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…
kew
// async test
var d = kew.defer()
var code = 'kew' + 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…
Native
// async test
try {
var code = 'native' + Math.random();
var p = new Promise(function(resolve, reject) {
  function eventFunc(e) {
    if (e.data === code) {
      window.removeEventListener('message', eventFunc);
      resolve();
    }
  }
  window.addEventListener('message', eventFunc);
});

p.then(function() {
  deferred.resolve()
})
window.postMessage(code, '*');
} catch(e) {
  // working around error handling issue https://github.com/mathiasbynens/jsperf.com/issues
  // an error will happen in IE (of course)
  // putting some code here so that the test doesn't think Native is the fastest (even if I have no way of telling jsperf the test errored)
  var n=0, callback
  setTimeout(callback=function() {
    if(n<3) {n++;setTimeout(callback,0)}
    else deferred.resolve()    
  },0)
  throw e
}
pending…
jquery
// async test
var code = 'jquery' + Math.random();
var d = $.Deferred()
function eventFunc(e) {
  if (e.data === code) {
    window.removeEventListener('message', eventFunc);
    d.resolve();
  }
}
window.addEventListener('message', eventFunc);
d.then(function done() {
  deferred.resolve()
})
window.postMessage(code, '*');
pending…
when.js
// async test
var code = 'jquery' + Math.random();

var d = when.defer()
window.addEventListener('message', function eventFunc(e) {
  if (e.data === code) {
    window.removeEventListener('message', eventFunc);
    d.resolve()
  }
});

d.promise.then(function done() {
  deferred.resolve()
})
window.postMessage(code, '*');
pending…
async-future
// async test
var code = 'jquery' + Math.random();

var d = new asyncFuture
window.addEventListener('message', function eventFunc(e) {
  if (e.data === code) {
    window.removeEventListener('message', eventFunc);
    d.return()
  }
});

d.then(function() {
  deferred.resolve()
}).done()
window.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.

0 Comments

//kew 0.5.0-alpha1