Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
for vs foreach vs for..in vs for..of with Map and 1 million entry
Compare loop performance with a small load with Map object and 1 million entry Note: for-in do not work with Map
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 26_5_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) EdgiOS/149.0.4022.96 Version/26.0 Mobile/15E148 Safari/604.1
Browser:
Mobile Safari 26
Operating system:
iOS 26.5.0
Device Platform:
Mobile
Date tested:
26 days ago
forEach
108/s
for-of
98/s
for-i
43/s
View exact numbers
Test name
Executions per second
✓
forEach
108 Ops/sec
for-of
98 Ops/sec
for-i
43 Ops/sec
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const map = new Map(); for (let i = 0; i < 1000000; i++) { map.set(i, Math.random() * 1000); }
Tests:
for-i
for (let i = 0; i < map.size; i++) { const value = map.get(i); const str = value.toString(10); }
forEach
map.forEach((value, key) => { const str = value.toString(10); });
for-of
for (const [key, value] of map) { const str = value.toString(10); }