Promise vs Callback

JavaScript performance comparison

Revision 7 of this test case created by

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
Promise
// async test
var d = deferred;
var l = 1000;
var a = [];

while(l--) {
    a.push(getData());
}

function getData() {
  return new Promise(function(resolve) {
    setTimeout(function() {
      resolve('data')
    }, 0);
  })
}


Promise.all(a).then(function(data) {
  d.resolve()
})
pending…
Callback
// async test
var d = deferred;
var l = 1000;
var a = [];

function getData(callback) {
  setTimeout(function() {
    callback('data')
  }, 0)
}

function cb() {
    l++
    if (l === 999) {
        d.resolve();
    }
    
}

while(l--) {
    a.push(getData(cb));
}
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