Promise vs Callback (v27)

Revision 27 of this benchmark created on


Setup

var nextTick = (function () {
        var el = document.createElement('div');
        var cb;
        new MutationObserver(function () {
            cb();
        }).observe(el, { attributes: true });
        return function (callback) {
            cb = callback;
            el.setAttribute('x', 'y');
        };
    }());
    
    var cb = function (deferred) {
      nextTick(function () {
        deferred.resolve('data');
      });
    };
    
    var promise = function (deferred) {
      Promise.resolve('data').then(function (val) {
        nextTick(function () {
          deferred.resolve(val);
        });
      });
    };

Test runner

Ready to run.

Testing in
TestOps/sec
Callback
// async test
cb(deferred);
ready
Promise
// async test
promise(deferred);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.