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

Revision 21 of this benchmark created on


Preparation HTML

<script>
var f = function() {
  return [];
};

var that = {
  f: f
};

var bound = f.bind(that);

var wrappedCall = function() {
  f.call(that);
};

var slice = Array.prototype.slice;

var name = 'f';
function bindMethod(that, name) {
  return function () {
    return that[name]();
  };
}
var byName = bindMethod(that, name);
</script>

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
by string
that['f']();
ready
by string (indirect)
that[name]();
ready
direct (local)
f();
ready
Wrapped Call
wrappedCall();
ready
call by string
that['f'].call(that);
ready
bind inline
f.bind(that)();
ready
byName
byName()
ready

Revisions

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