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

Revision 19 of this benchmark created by Eamon Nerbonne on


Description

Testing various ways to invoke a function, including several ways to manipulate its 'this'.

(2013-12-07 Removed buggy bind2 implementation what was distorting the results)

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';
</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

Revisions

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