Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
simple array and map vs forEach vs for by cuteLuna v4
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser:
Chrome 120
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
map
14881164.0 Ops/sec
foreach
17406952.0 Ops/sec
for
3915423.8 Ops/sec
Script Preparation code:
var arr = [{ name: 'luna', id: 3 },{ name: 'abc', id: 4 }, { name: 'eee', id: 3 }]
Tests:
map
const newArr = [] const temp = arr.map((item, index) => { newArr[index] = {label: item.name, id: item.id} })
foreach
const newArr = []; arr.forEach((item, index) => { newArr[index] = {label: item.name, id: item.id} })
for
const arrLength = arr.length; const newArr = []; for (let i = 0; i < arrLength; i++) { newArr[i] = {label: arr[i].name, id: arr[i].id} }