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 (Windows NT 10.0; Win64; x64; rv:152.0) Gecko/20100101 Firefox/152.0
Browser:
Firefox 152
Operating system:
Windows
Device Platform:
Desktop
Date tested:
28 days ago
for-in
94.4M/s
forEach
213/s
for-i
46/s
for-of
13/s
View exact numbers
Test name
Executions per second
✓
for-in
94,411,600 Ops/sec
forEach
213 Ops/sec
for-i
46 Ops/sec
for-of
13 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); }