Promise vs Callback vs Fastsync

JavaScript performance comparison

Revision 21 of this test case created by Karl Kirch

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  !function(n){function t(n,r,l){return function(){var u=Array.prototype.slice.call(arguments);return u[0]?l(u[0]):r[n+1]?(u.shift(),u.push(t(n+1,r,l)),r[n+1].apply(null,u)):l.apply(null,u)}}function r(n,t,l,u){return function(a,e){return a?u(a):(l[n]=e,t[n+1]?t[n+1](r(n+1,t,l,u)):u(null,l))}}function l(n,t){var r,l=0,u=[];return function(a,e,f){u[a]=f,e&&(r=e,t(e)),r||++l!=n||t(null,u)}}function u(n,t){return function(r,l){t(n,r,l)}}n.parallel=function(n,t){var r=n.length,a=0,e=l(r,t);for(a;r>a;++a)n[a](u(a,e))},n.serial=function(n,t){var l=(n.length,0),u=[];n[l](r(l,n,u,t))},n.waterfall=function(n,r){var l=(n.length,0);n[l](t(l,n,r))},n.asyncMap=function(t,r,l){var u=[],a=0;for(a;a<t.length;++a)u[a]=r.bind(null,t[a]);n.parallel(u,l)}}("undefined"==typeof exports?this.fastsync=this.fastsync||{}:exports);
  
  fastsync = this.fastsync;

};
</script>

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

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

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

fastsync.parallel(a, function(){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.

0 Comments