bind vs custom

JavaScript performance comparison

Revision 2 of this test case created by Emil Pirfalt

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var r;
  var object = { 'x': 3 };
  
  function bind(fn, thisArg) {
    return function() {
      var args = []
      for(var i = 0, l = arguments.length; i < l; i++) {
        args[i] = arguments[i]
      }
      return fn.apply(thisArg, args);
    };
  }
  
  function callback(num) {
    return this.x + num;
  }
  
  var nativeBound = callback.bind(object);
  var customBound = bind(callback, object);
  

};
</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
native bind
r = nativeBound(2);
pending…
custom bind
r = customBound(2);
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