compare when/function.apply implementations

JavaScript performance comparison

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 CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Original
executeTestCases(function(func, args) {
  return when.all(args).spread(func);
});
pending…
Without all
executeTestCases(function(func, args) {
  return when(args).spread(func);
});
pending…
Without spread
var undef = void 0;

executeTestCases(function(func, args) {
  return when.all(args).then(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.

0 Comments