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

Revision 71 of this benchmark created on


Setup

function f(){
    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.