Shallow array copy

Benchmark created on


Description

Test various ways of performing a shallow array copy.

Setup

const arr = new Array(10000);
arr.map(v => Math.round(Math.random() * 100));
const swap = [...arr];

Test runner

Ready to run.

Testing in
TestOps/sec
Spread operator
const arr2 = [...arr];
ready
Concat
const arr2 = [].concat(arr);
ready
Use swap array
swap.length = 0;
const arr2 = swap.concat(arr);
ready

Revisions

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