Duplicate array (slice vs concat) (v5)

Revision 5 of this benchmark created by Paul Grenier on


Setup

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

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, i=-1, res = [];
while (++i < len) {
    res[i] = arr[i];
}
ready
while push
var i = arr.length+1, res = [];
while (--i) {
    res.push(arr[i]);
}
ready
Slice(0)
var res = arr.slice(0)
ready
push apply
var res = [];
res.push.apply(res, arr);
ready
while buffer
var i = arr.length, res = new Array(i);
while (i--) {
    res[i] = arr[i];
}
ready

Revisions

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