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

Revision 87 of this benchmark created by Arne Babenhauserheide on


Setup

function f() {
    return this;
  }
  var that = {
    f: f
  };
  var bound = f.bind(that);
  var that2 = Object.create(that);
  var that3 = {};
  var that4 = Object.create(that3);
  
  function A() {
    this.bar = "bar";
  }
  A.prototype.foo = function() {
    return this.bar;
  }
  
  function B() {}
  B.prototype = Object.create(A.prototype);
  B.prototype.constructor = B;
  var b = new B();
  var bound = A.prototype.foo.bind(b);

Test runner

Ready to run.

Testing in
TestOps/sec
call
A.prototype.foo.call(b);
ready
bind
var newBound = A.prototype.foo.bind(b);
newBound();
ready
bound
bound();
ready
bind
bound();
ready
prototype
that2.f();
ready
direct (dynamic property)
that3.f = f;
that3.f();
ready
prototype (dynamic property)
that3.f = f;
that4.f();
ready
in closure
// async test
(function() {
  (function() {
    (function() {
      return that2.f();
    })();
  })();
})();
ready
direct
f();
ready

Revisions

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