bind vs closure

JavaScript performance comparison

Revision 46 of this test case created by kyle

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var MyObject = function(){
    this.a = 1;
  };
  
  MyObject.prototype.foo = function(){
    this.a++;
  };
  
  var Eventer = function(){};
  Eventer.prototype.callback = function(){};
  
  
  var normalObject = new MyObject();
  var boundObject = new MyObject();
  boundObject.foo = boundObject.foo.bind(boundObject);
  
  var closureEventer = new Eventer();
  closureEventer.callback = function(){
    normalObject.foo();
  };
  
  var boundEventer = new Eventer();
  boundEventer.callback = boundObject.foo;
  

};
</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
with bound invocation
boundEventer.callback();
pending…
with anonymous closure
closureEventer.callback();
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