direct call vs apply

JavaScript performance comparison

Revision 2 of this test case created by Joshua T Kalis

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function add_w_apply_arguments(a, b) {
      return _add.apply(this, arguments)
    }
   
    function add_w_apply(a, b) {
      return _add.apply(this, [a, b])
    }
   
    function add_w_call(a, b) {
      return _add.call(this, a, b)
    }
   
    function _add(a, b) {
      return a + b
    }
   
    var x
};
</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 call
x = _add(3, 4)
pending…
apply using arguments
x = add_w_apply_arguments(3, 4)
pending…
apply NOT using arguments
x = add_w_apply(3, 4)
pending…
call
x = add_w_call(3, 4)
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