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 (iPhone; CPU iPhone OS 16_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.3 Mobile/15E148 Safari/604.1
Browser:
Mobile Safari 16
Operating system:
iOS 16.3.1
Device Platform:
Mobile
Date tested:
2 years ago
Test name
Executions per second
map
3620804.2 Ops/sec
foreach
4663195.0 Ops/sec
for
1458387.6 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} }