bind vs closure

JavaScript performance comparison

Revision 57 of this test case created by

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/dojo/1/dojo/dojo.xd.js">
</script><script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script>
  function foo() {}
</script>
      
<script>
Benchmark.prototype.setup = function() {
  var binder = function(scope, method) {
    return function() {
       return method.apply(scope, arguments);
    }
  };
  
  var self = this;
  var test = function() { return this; }
  
  var test_bind = test.bind(self);
  var test_self = function() { return self; };
  var test_dojo = dojo.hitch(self, test);
  var test_binder = binder(self, test);
  var test_underscore = _.bind(test, self);

};
</script>

Preparation code output

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
bind()
test_bind();
pending…
self
test_self();
pending…
dojo.hitch
test_dojo();
pending…
binder
test_binder();
pending…
call (control)
test.call(this);
pending…
underscore
test_underscore()
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