copy simple array (v3)

Revision 3 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
push
b = [];
Array.prototype.push.apply(b, a);
ready

Revisions

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