Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
js array copy speed comparison v3
(version: 0)
Comparing performance of:
map vs array.from vs for loop vs foreach vs slice vs slice(0)
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
map
const arr = [1,2,3,4,5] const newArr = arr.map(e=>e)
array.from
const arr = [1,2,3,4,5] const newArr = Array.from(arr)
for loop
const arr = [1,2,3,4,5] let newArr = []; for(let i = 0; i < arr.length; i++) { newArr[i] = arr[i]; }
foreach
const arr = [1,2,3,4,5] let newArr = [] arr.forEach(e => { newArr.push(e) })
slice
const arr = [1,2,3,4,5] const newArr = arr.slice()
slice(0)
const arr = [1,2,3,4,5] const newArr = arr.slice(0)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (6)
Previous results
Fork
Test case name
Result
map
array.from
for loop
foreach
slice
slice(0)
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
Lodash cloneDeep vs. Lodash clone vs. Array.slice() vs. Array.slice(0) vs. Object.assign()
Array shallow copy - slice(0) vs conditional for() loop
JavaScript array copy via spread op vs slice
Slice vs spread array
JavaScript Large Array Copy
Comments
Confirm delete:
Do you really want to delete benchmark?