Q.promise vs safejs

JavaScript performance comparison

Test case created by Sergey Korotkov

Info

Q.promises libaray is very reach and promising :)... However sometime its better to keep development in callback style but still it is good to offload routine work to some libray. We develop safe.js library that does this and plays nice standalone or in conjunction with async.js. It doesn't provide everything that has Q.promises but still helps to write nice reading and error proof (meaning exception handling and callback hell) Here is the test that does the same as we think on Q.promises and safe.js

Preparation code

<script src="https://s3.amazonaws.com/pushok-outbox/jsperf/q.min.js"></script>
<script type="text/javascript" src="https://s3.amazonaws.com/pushok-outbox/jsperf/safe.min.js"></script>
<script>
Benchmark.prototype.setup = function() {
    function worker(cb) {
      cb();
    }
};
</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
Q promises
// async test
Q.
try (function() {
  return Q.nfcall(worker)
    .then(Q.nfcall(worker))
    .then(Q.nfcall(worker))
    .then(Q.nfcall(worker))
}).
finally(function() {
  deferred.resolve()
})
pending…
safejs
// async test
safe.wrap(function(cb) {
    worker(safe.sure(cb, function() {
      worker(safe.sure(cb, function() {
        worker(safe.sure(cb, function() {
          worker(cb)
        }))
      }))
    }))
  },
  function(err) {
    deferred.resolve()
  })()
pending…

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

Compare results of other browsers

0 comments

Add a comment