function calls: direct vs apply vs call vs bind

JavaScript performance comparison

Revision 19 of this test case created by Eamon Nerbonne

Info

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 code

<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

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
direct
that.f();
pending…
apply
f.apply(that);
pending…
call
f.call(that);
pending…
bind
bound();
pending…
by string
that['f']();
pending…
by string (indirect)
that[name]();
pending…
direct (local)
f();
pending…
Wrapped Call
wrappedCall();
pending…
call by string
that['f'].call(that);
pending…
bind inline
f.bind(that)();
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment