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

Revision 76 of this benchmark created by pcowdogg on


Preparation HTML

<script src="//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(){
            return f.call(scope, arguments[0]);
        }
    };
    var bindApply = function(f, scope){
        return function(){
            return f.apply(scope, arguments);
        }
    };
    var bindScope = function(f, scope){
        return function(){
            return 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);
    
    var n = {
        value: 1,
        sum: function(x) {
            return this.value + x;
        }
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Native bind
t1(1);
ready
loDash bind
t2(1)
ready
Custom Bind With Call
t3(1)
ready
Custom Bind With Apply
t4(1)
ready
Custom Bind With Scope
t5(1)
ready
Method Call
n.sum(1)
ready

Revisions

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