Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
js array copy speed comparison and spread operator
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0
Browser:
Firefox 128
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
slice
14K/s
for loop
9K/s
map
8K/s
spread
7K/s
array.from
7K/s
foreach
7K/s
View exact numbers
Test name
Executions per second
✓
slice
13,869 Ops/sec
for loop
9,084 Ops/sec
map
8,245 Ops/sec
spread
7,406 Ops/sec
array.from
7,072 Ops/sec
foreach
6,678 Ops/sec
Tests:
map
const arr = Array.from({ length: 10_000 }, (_, i) => i) const newArr = arr.map(e=>e)
array.from
const arr = Array.from({ length: 10_000 }, (_, i) => i) const newArr = Array.from(arr)
for loop
const arr = Array.from({ length: 10_000 }, (_, i) => i) let newArr = []; for(let i = 0; i < arr.length; i++) { newArr[i] = arr[i]; }
foreach
const arr = Array.from({ length: 10_000 }, (_, i) => i) let newArr = [] arr.forEach(e => { newArr.push(e) })
slice
const arr = Array.from({ length: 10_000 }, (_, i) => i) const newArr = arr.slice()
spread
const arr = Array.from({ length: 10_000 }, (_, i) => i) const newArr = [...arr]