arguments vs. Arguments vs. call by key

JavaScript performance comparison

Revision 3 of this test case created by Sebastian Markbåge

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function testMethod(a, b, c) {
    return a + b + c;
  }
  
  function variadicBind(method) {
    var context = this;
    return function() {
      return method.apply(context, arguments);
    };
  }
  
  function restrictBind(method) {
    var context = this;
    return function(a, b, c, d, e, tooMany) {
      return method.call(context, a, b, c, d, e);
    };
  }
  
  function keyBind(key) {
    var context = this;
    return function(a, b, c, d, e, tooMany) {
      return context[key](a, b, c, d, e);
    };
  }
  
  function tempBind(method) {
    var context = this;
    return function(a, b, c, d, e, tooMany) {
      context.tempMethod = method;
      return context.tempMethod(a, b, c, d, e);
    };
  }
  
  var obj = {
    variadicBind: variadicBind,
    restrictBind: restrictBind,
    keyBind: keyBind,
    tempBind: tempBind,
    testMethod: testMethod,
    tempMethod: function() {}
  };
  
  var variadicBound = obj.variadicBind(testMethod);
  var restrictBound = obj.restrictBind(testMethod);
  var keyBound = obj.keyBind('testMethod');
  var tempBound = obj.tempBind(testMethod);

};
</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
Temp Method
var i = tempBound(1, 2, 3);
pending…
Bound By Method Key
var i = keyBound(1, 2, 3);
pending…
Arguments
var i = variadicBound(1, 2, 3);
pending…
Restricted Arguments
var i = restrictBound(1, 2, 3);
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