Native bind vs lodash vs call vs apply vs closure scope (v58)

Revision 58 of this benchmark created on


Preparation HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/0.8.1/lodash.min.js">
</script>
<script>
  var lodash = _.noConflict();
</script>

Setup

var bindCall = function(f, scope){
        return function(){
            f.call(scope, arguments[0]);
        }
    };
    var bindApply = function(f, scope){
        return function(){
            f.apply(scope, arguments);
        }
    };
    var bindScope = function(f, scope){
        return function(){
            f(scope, arguments[0]);
        }
    };
    var t1 = (function(x) {
      return this + x;
    }).bind(1);
    
    var t2 = lodash.bind(function(x) {
      return this + x;
    }, 1);
    
    var t3 = bindCall(function(x) {
        return this + x;
    }, 1);
    
    var t4 = bindApply(function(x) {
        return this + x;
    }, 1);
    var t5 = bindScope(function(scope, x) {
        return scope + x;
    }, 1);

Test runner

Ready to run.

Testing in
TestOps/sec
Native bind
t1(1);
ready
loDash bind
t2(1)
ready

Revisions

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