arguments performance

JavaScript performance comparison

Test case created by Kooi

Info

check Array.prototype.slice vs named arguments

Preparation code

<script>
  function arg1(a, b, c) {
   return Array.prototype.slice.call(arguments);
  }
 
  function arg2(a, b, c) {
   var args = [],
       l = arguments.length;
   while (l--) {
    args.push(arguments[l]);
   }
   return args;
  }
 
  function arg3(a, b, c) {
   return [a, b, c];
  }
 
  function moreArg(a, b, c) {
   return [a, b, c, arguments[3], arguments[4]];
  }
</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
slice arguments
var myargs = arg1(1, 2, 3);
pending…
arguments2array
var myargs = arg2(1, 2, 3)
pending…
named args
var myargs = arg3(1, 2, 3)
pending…
more arguments
var myargs = moreArg(1, 2, 3, 4, 5);
pending…
just use arguments
var myargs = (function() {
 return [arguments[0], arguments[1], arguments[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. Here’s a list of current revisions for this page:

0 comments

Add a comment