lodash thisArg vs bind vs closure (v5)

Revision 5 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)
_.forEach(array, foo.bind(this));
ready
_.bind(foo,this)
_.forEach(array, _.bind(foo, this));
ready
self = this
var self = this;
_.forEach(array, function() {
    foo(this);
});
ready

Revisions

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