function calls: direct vs apply vs call

JavaScript performance comparison

Revision 83 of this test case created by Roland Pihlakas

Preparation code

<script>
var a = [1, 2, 3];
var b = [];
var obj = {
    foo: function () {
        var len = arguments.length;
        return this.bar;
    },
    bar: 'baz'
};
</script>
    

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
direct
obj.foo(1, 2, 3);
pending…
apply
obj.foo.apply(obj, a);
pending…
call
obj.foo.call(obj, 1, 2, 3);
pending…
apply-like call
obj.foo.call(obj, a[0], a[1], a[2]);
pending…
apply-like call, unknown arguments
obj.foo.call(obj, b[0], b[1], b[2]);
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.

0 Comments