Call vs bind vs closure

JavaScript performance comparison

Revision 2 of this test case created by polotek

Preparation code

<script>
  var testClass = {
   funcA: function() {
    return 1;
   }
  };
 
  var proxy = function(fn, scope) {
   if (!scope) scope = this;
   return function() {
    return fn.apply(scope, arguments);
   };
  };
 
  var funcAClosure = proxy(testClass.funcA, testClass);
 
  var funcABind = testClass.funcA.bind(testClass);
</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
Func.call
var funcA = testClass.funcA;

funcA.call(testClass);
pending…
Closure
funcAClosure();
pending…
Bind
funcABind();
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:

2 comments

polotek (revision owner) commented :

Added native bind test. Will fail in older browsers.

Stephan Beal commented :

Sorry, Chrome. i love you, but my slow netbook just absolutely ruined your average scores :(. (@Readers: Chrome 10.x was at the top in all categories except "Func call" before i ran this on my netbook.)

Add a comment