arguments to array

JavaScript performance comparison

Revision 10 of this test case created

Preparation code

<script>
var f1 = function () {
  return [].slice.call(arguments);
};

var f2 = function () {
  return Array.prototype.slice.call(arguments);
};

var f3 = function () {
  var args = [];
  for (var i = 0, l = arguments.length; i < l; i++) {
    args.push(arguments[i]);
  }
  return args;
};

var f3_help = function (a) {
  var args = [];
  for (var i = 0, l = a.length; i < l; i++) {
    args.push(a[i]);
  }
  return args;
};

var f3_call = function() {
  return f3_help(arguments);
}

var f4 = function () {
  var args = [];
  for (var i = 0, l = arguments.length; i < l; i++) {
    args[i] = arguments[i];
  }
  return args;
};

var f5 = function () {
  var args = new Array(arguments.length);
  for (var i = 0, l = arguments.length; i < l; i++) {
    args[i] = arguments[i];
  }
  return args;
};

var f5_help = function(a) {
  var args = new Array(a.length);
  for (var i = 0, l = a.length; i < l; i++) {
    args[i] = a[i];
  }
  return args;
};

var f5_call = function() {
  return f5_help(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
f1
f1(1, 2, 3, 4, 5);
pending…
f2
f2(1, 2, 3, 4, 5);
pending…
f3
f3(1, 2, 3, 4, 5);
pending…
f4
f4(1, 2, 3, 4, 5);
pending…
f5
f5(1, 2, 3, 4, 5);
pending…
f3_call
f3_call(1, 2, 3, 4, 5);
pending…
f5_call
f5_call(1, 2, 3, 4, 5);
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