function calls: direct vs apply vs call vs bind

JavaScript performance comparison

Revision 14 of this test case created by drkibitz

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    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);
};
</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…
prototype
that2.f();
pending…
direct (dynamic property)
that3.f = f; that3.f();
pending…
prototype (dynamic property)
that3.f = f; that4.f();
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