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

Revision 16 of this benchmark created on


Setup

function f() {
        return this;
    }
    var that = {
        f: f
    };
    var bind = function(f, ctx) {
      return function() {
        return f.apply(ctx, arguments);
      };
    };
    var rawBound = bind(f, that);
    var bound = f.bind(that);
    var that2 = Object.create(that);
    var that3 = {};
    var that4 = Object.create(that3);

Test runner

Ready to run.

Testing in
TestOps/sec
direct
that.f();
ready
apply
f.apply(that);
ready
call
f.call(that);
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
manually bound
rawBound();
ready

Revisions

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