Duplicate array (slice vs concat) (v15)

Revision 15 of this benchmark created on


Setup

var arr = [];
    for (var i = 0; i < 12500; i++) {
      arr.push(true, false, true, false, 1, 2, 3, 4);
    }
    // 12500x8 = 1 000 000 elements
    
    var slice = arr.slice;

Test runner

Ready to run.

Testing in
TestOps/sec
Concat
var res = arr.concat();
ready
Slice
var res = arr.slice()
ready
while [ ]
var len = arr.length,
  res = Array(len);
for (var i = 0; i < len; i++) {
  res[i] = arr[i];
}
ready
while push
var res = [];
for (var i = 0, len = arr.length; i < len; i++) {
  res.push(arr[i]);
}
ready
[] desc
var len = arr.length,
  res = Array(len);
while (len--) {
  res[len] = arr[len];
}
ready
Slice call
slice.call(arr);
ready

Revisions

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