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
foreach
4.7M/s
map
3.6M/s
for
1.5M/s
View exact numbers
Test name
Executions per second
✓
foreach
4,663,195 Ops/sec
map
3,620,804 Ops/sec
for
1,458,388 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} }