bind vs closure invocation

JavaScript performance comparison

Revision 7 of this test case created by erwerwer

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/dojo/1/dojo/dojo.xd.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.3.0/lodash.min.js"></script>
<script>
var esBind = (function(){ return this }).bind(this);
var closureBind = (function() {
  var self = this;
  return function(){ return self };
})()
var dojoHitch = dojo.hitch(this, function(){ return this });
var lodashBind = _.bind(function () { return this }, this);
var myBind1 = bind0arg1(this, function() { return this });
var myBind2 = bind0arg2(this, function() { return this });

function bind0arg1(scope, fn){
  return function() { return fn.call(scope); }
}function bind0arg2(scope, fn){
  return function() { return fn.apply(scope); }
}
</script>

Preparation code output

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()
esBind();
pending…
self
closureBind();
pending…
dojo.hitch
dojoHitch();
pending…
lodash.bind
lodashBind();
pending…
mybind 1
myBind1();
pending…
mybind 2
myBind2();
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. Here’s a list of current revisions for this page:

0 comments

Add a comment