lodash thisArg vs bind vs closure (v7)

Revision 7 of this benchmark created on


Preparation HTML

<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/1.2.1/lodash.min.js" ></script>

Setup

var array = [];
    var obj = {}
    
    for (var i = 0; i < 10000; i++) {
      array[i] = i;
      obj[i] = i;
    }
    
    
    function foo(x) {
      return x * 2;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
foo.bind(this)
_.each(array, _.bind(foo, this));
ready
_.bind(foo,this)
_.forEach(array, _.bind(foo, this));
ready
self = this
var self = this;
_.forEach(array, function() {
    foo(self);
});
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.