Quick apply vs call vs bind

JavaScript performance comparison

Test case created by Josh Vermaire

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function func()  {
      return this;
    }
   
    var obj = {
      func: func
    }
};
</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
Apply
function test() {
  return func.apply(obj);
}

test();
pending…
Call
function test() {
  return func.call(obj);
}

test();
pending…
Closure Apply
function test(object) {
  return function() {
    return func.apply(object);
  }
}

test(obj)();
pending…
Closure Call
function test(object) {
  return function() {
    return func.call(object);
  }
}

test(obj)();
pending…
Bind
func.bind(obj)();
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment