Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
for vs foreach vs for..in vs for..of with Map and 1 million entry
(version: 2)
Compare loop performance with a small load with Map object and 1 million entry Note: for-in do not work with Map
Comparing performance of:
for-i vs forEach vs for-of
Created:
28 days ago
by:
Registered User
Go to the latest result
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); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
for-i
forEach
for-of
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
26 days ago
)
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/OS:
Mobile Safari 26 on iOS 26.5.0
View result in a separate tab
Embed
Embed Benchmark Result
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
Related benchmarks
Iterate Map entries
for vs foreach vs for..in vs for..of, 1m
Comments
Confirm delete:
Do you really want to delete benchmark?