Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
array iteration vs map + filter vs for..of vs for loop
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:140.0) Gecko/20100101 Firefox/140.0
Browser:
Firefox 140
Operating system:
Linux
Device Platform:
Desktop
Date tested:
7 months ago
Test name
Executions per second
forEach
15592.1 Ops/sec
map
15163.5 Ops/sec
for..of
15461.5 Ops/sec
for loop
15637.4 Ops/sec
Script Preparation code:
const obj = (id, data = false) => ({ data: data ? {} : undefined, id }) const array = [...Array.from({ length: 10 })].map((_, i) => obj(i, i % 2 === 0))
Tests:
forEach
array.forEach((value, index) => { if (value.data) { console.log(value) } })
map
array.filter(({ data }) => !!data).map((value, index) => { console.log(value) })
for..of
for (const value of array) { if (value.data) { console.log(value) } }
for loop
for (let i = 0; i < array.length; i++) { if (array[i].data) { console.log(array[i]) } }