Calling function vs apply with arguments

JavaScript performance comparison

Revision 2 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var target = function(a, b, c, d) {
        return [a, b, c, d];
        };
   
    var simple = function(a, b, c, d) {
        return target(a, b, c, d);
        };
   
    var complex = function() {
        return target.apply(null, arguments);
        }
       
       
       
    var fixed_complex = function(a, b, c, d) {
        return target.apply(null, arguments);
        }
};
</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
Simple
var m = simple(1, 2, 3, 4);
pending…
Simple, partial
var m = simple(1, 2);
pending…
Complex
var m = complex(1, 2, 3, 4);
pending…
Complex, partial
var m = complex(1, 2);
pending…
Fixed Complex
var m = fixed_complex(1, 2, 3, 4);
pending…
Fixed Complex, partial
var m = fixed_complex(1, 2);
pending…
Simple, partial undefined
var m = simple(1, 2, undefined, undefined);
pending…
Complex, partial undefined
var m = complex(1, 2, undefined, undefined);
pending…
Fixed Complex, partial undefined
var m = fixed_complex(1, 2, undefined, undefined);
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