The arguments object (v13)

Revision 13 of this benchmark created by Klaus on


Description

How slow is the use of arguments?

Preparation HTML

<script>
  function a() {
    return [arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5], arguments[6], arguments[7], arguments[8], arguments[9]];
  }

  function c(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) {
    return [arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9];
  }

  function d(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) {
    var arguments;
    return [arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9];
  }

  function e(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arguments) {
    return [arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9];
  }
  function o(args) {
    var arr = [];
    for (var i=0, arr = [], total = args.length; i<total; i++)
    {
       arr.push(args[i]);
    }
    return arr;
  }
  function s() {
    return Array.prototype.slice.call(arguments);
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
arguments object, accessing individual args
a('foo', 'bar', 42);
ready
Regular arguments
c('foo', 'bar', 42);
ready
Regular arguments (var arguments)
d('foo', 'bar', 42);
ready
Regular arguments (arguments in args)
e('foo', 'bar', 42);
ready
Object arguments
o(['foo', 'bar', 42]);
ready
Convert Arguments to Array
s('foo', 'bar', 42);
ready

Revisions

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