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 unknown unknown
Test Ops/sec
Arguments
var i = variadicBound(1, 2, 3);
pending…
Restricted Arguments
var i = restrictBound(1, 2, 3);
pending…
Bound By Method Key
var i = keyBound(1, 2, 3);
pending…
Temp Method
var i = tempBound(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. Here’s a list of current revisions for this page:

0 comments

Add a comment