bind vs apply fn

JavaScript performance comparison

Test case created

Preparation code

<script>

function increment(x){
   this.index += x || 1;
}

function bind(fn, ctx){
   return function(){
     return fn.apply(ctx, arguments);
   }
}

var obj = {
  index: 0
}

</script>
<script>
Benchmark.prototype.teardown = function() {
    obj.index = 0;
};
</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
bind
var fn = increment.bind(obj);
fn(2);
pending…
apply fn
var fn = bind(increment, obj);
fn(2)
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