Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
for vs for ... of vs forEach vs map
Compare loop performance
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:144.0) Gecko/20100101 Firefox/144.0
Browser:
Firefox 144
Operating system:
Mac OS X 10.15
Device Platform:
Desktop
Date tested:
9 months ago
for
1.9M/s
forEach
1.5M/s
map
1.4M/s
for ... of
648K/s
View exact numbers
Test name
Executions per second
✓
for
1,920,804 Ops/sec
forEach
1,508,786 Ops/sec
map
1,379,894 Ops/sec
for ... of
648,472 Ops/sec
Script Preparation code:
const array = Array.from({ length: 100 }, (_, i) => i) const result = []
Tests:
for
const result = [] for (let i = 0; i < array.length; i++) { result.push(array[i] * 2) }
for ... of
const result = [] for (const value of array) { result.push(value * 2) }
forEach
const result = [] array.forEach((value) => { result.push(value * 2) })
map
const result = array.map((value) => value * 2)