function calls: direct vs apply vs call vs bind (v51)

Revision 51 of this benchmark created by Roland on


Setup

var f = function(){
      return this;
    };
    
    function bind (self, fn) {
        
        return function () {
            return fn.apply(self, arguments);
        };
    }
    
    function wrapped () {
        return f();
    }
    
    function cBind (self, fn) {
        
        return function (callback) {
            return fn.call(self, callback);
        };
    }
    
    var that = {};
    
    var bound = f.bind(that);
    
    var cBound = bind(that, f);
    var ccBound = cBind(that, f);

Test runner

Ready to run.

Testing in
TestOps/sec
direct
f();
ready
apply
f.apply(that);
ready
call
f.call(that);
ready
bind
bound();
ready
custom bind
cBound();
ready
custom bind 2
ccBound();
ready
wrapped
wrapped();
ready

Revisions

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