Shallow cloning array

Benchmark created on


Description

test to compare difference between JSON.parse(JSON.stringify(myArray)) and [...myArray]

Setup

const myArray = [];
for (let i = 0; i < 10000; i += 1) {
	myArray.push(i);
}

Test runner

Ready to run.

Testing in
TestOps/sec
JSON
for (let i = 0; i < 10000; i += 1) {
	const dupe = JSON.parse(JSON.stringify(myArray));
}
ready
spread
for (let i = 0; i < 10000; i += 1) {
	const dupe = [...myArray];
}
ready
structuredClone
for (let i = 0; i < 10000; i += 1) {
	const dupe = structuredClone(myArray);
}
ready

Revisions

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