Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
for..of against Map.entries vs for..in 2
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.1.2 Safari/605.1.15
Browser:
Safari 17
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
for..of Map.entries()
4306.9 Ops/sec
Map.foreach
4844.1 Ops/sec
for..of Map.entries() no destructuring
4258.5 Ops/sec
Script Preparation code:
var array = Array.from({ length: 10000 }, () => { const n = Math.floor(Math.random() * 100) if (n > 26) { return n } else { return String.fromCharCode('a'.charCodeAt(0) + n); } }); var obj = new Map(); for (let i = 0; i < array.length; i++) { obj.set(i, array[i]); }
Tests:
for..of Map.entries()
for (const [key, val] of obj.entries()) { const foo = val + 'a'; }
Map.foreach
obj.forEach((val) => { const foo = val + 'a'; })
for..of Map.entries() no destructuring
for (const entry of obj.entries()) { const key = entry[0]; const val = entry[1]; const foo = val + 'a'; }