Duplicate array (slice vs concat) (v3)

Revision 3 of this benchmark created by Rob W 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

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

Revisions

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