copy simple array (v4)

Revision 4 of this benchmark created on


Description

Quickest way to get a byval copy of an array of simple values - will NOT copy immutable objects in arrays byval e.g. nested arrays / objects etc get copied BYREF.

Setup

var a = [1, 2, 3, 4, 5, 6, 7, 8, 9],
      b = null;

Test runner

Ready to run.

Testing in
TestOps/sec
concat
b = a.concat();
ready
slice w/index
b = a.slice(0);
ready
slice w/o index
b = a.slice();
ready
[]
b = [].concat(a);
ready
new Array
b = new Array(a.join());
ready
loop
var i = a.length,
  b = [];
for (;
  (i);) {
  --i;
  b.push(a[i]);
}
ready
var i = a.length,
  b = [];
while (i--) {
  b.push(a[i]);
}
ready

Revisions

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