Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Map.keys() + Map.get() vs. Map.forEach() vs. Map.entries()
(version: 1)
Comparing performance of:
keys() + get() vs forEach() vs entries()
Created:
2 days ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
// Bereite eine globale Test-Map mit 50 Einträgen vor const LIST_CACHE = new Map(); for (let i = 0; i < 50; i++) { const itemMock = { id: `item_${i}`, maxStack: 99, isUnique: false }; LIST_CACHE.set(itemMock, Math.floor(Math.random() * 10) + 1); } // Minimaler Mock für die #has Methode des Inventars (gibt immer true zurück, um reinen Schleifen-Overhead zu messen) const inventoryMock = { has: function(item, count) { // Simuliere minimale Logik, damit der JIT die Schleife nicht wegoptimiert return item.maxStack > 0 && count > 0; } };
Tests:
keys() + get()
let allItemsMatch = true; for (const item of LIST_CACHE.keys()) { if (!inventoryMock.has(item, LIST_CACHE.get(item))) { allItemsMatch = false; break; } }
forEach()
let allItemsMatch = true; LIST_CACHE.forEach((count, item) => { if (!allItemsMatch) return; if (!inventoryMock.has(item, count)) { allItemsMatch = false; } });
entries()
let allItemsMatch = true; for (const [item, count] of LIST_CACHE) { if (!inventoryMock.has(item, count)) { allItemsMatch = false; break; } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
keys() + get()
forEach()
entries()
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 days ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:152.0) Gecko/20100101 Firefox/152.0
Browser/OS:
Firefox 152 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
keys() + get()
576448.6 Ops/sec
forEach()
1720948.1 Ops/sec
entries()
689539.6 Ops/sec
Comments
Confirm delete:
Do you really want to delete benchmark?