compare when/function.apply implementations

JavaScript performance comparison

Revision 2 of this test case created by Renato Zannon

Preparation code

<script src="https://raw.github.com/cujojs/when/1.8.0/when.js"></script>
<script>
Benchmark.prototype.setup = function() {
    var sum = function(a, b) {
      return a + b;
    };
   
    var testCases = [
      [10, 20],
      when.resolve([10, 20]),
      [when.resolve(10), when.resolve(20)],
      when.resolve([when.resolve(10), when.resolve(20)])
    ];
   
    function assertResult(result) {
      if(result != 30) {
        throw new Error("Wrong result! " + result);
      }
    };
   
    function executeTestCases(implem) {
      testCases.forEach(function(testCase) {
        implem(sum, testCase).then(assertResult).otherwise(function(reason) {
          console.error(reason);
        });
      });
    };
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
With 'then'
var undef = void 0;

executeTestCases(function(func, args) {
  return when.all(args).then(function(args) { return func.apply(undef, args); });
});
pending…
Without 'then'
var undef = void 0;

executeTestCases(function(func, args) {
  return when.all(args, function(args) { return func.apply(undef, args); });
});
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. Here’s a list of current revisions for this page:

0 comments

Add a comment