arguments[0] vs named param

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var push = Array.prototype.push;
   
    function withoutParam() {
        var count = arguments.length,
            args;
   
        if (count <= 1) {
            args = (count === 1) ? [arguments[1]] : [];
        } else {
            args = [];
            push.apply(args, arguments);
        }
   
        return args;
    }
   
    function withParam(data) {
        var count = arguments.length,
            args;
   
        if (count <= 1) {
            args = (count === 1) ? [data] : [];
        } else {
            args = [];
            push.apply(args, arguments);
        }
   
        return args;
    }
};
</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
withoutParam()
var args = withoutParam();
pending…
withParam()
var args = withParam();
pending…
withoutParam({...})
var args = withoutParam({ foo: 'bar' });
pending…
withParam({ ... })
var args = withParam({ foo: 'bar' });
pending…
withoutParam(1, 2, 3)
var args = withoutParam(1, 2, 3);
pending…
withParam(1, 2, 3)
var args = withParam(1, 2, 3);
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment