arr copy (v4)

Revision 4 of this benchmark created on


Setup

const arr = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", ]

Test runner

Ready to run.

Testing in
TestOps/sec
spread
const newArr = [...arr]
newArr[5] = "X"
ready
for loop push
const newArr = []

for(let i = 0; i < arr.length; i++) {
	newArr.push(arr[i])
}
newArr[5] = "X"
ready
for loop fixed arr
const newArr = new Array(arr.length)

for(let i = 0; i < newArr.length; i++) {
	newArr[i] = arr[i]
}
newArr[5] = "X"
ready
map
const newArr = arr.map((i) => i)
newArr[5] = "X"
ready

Revisions

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