Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Map.entries() vs. Map.forEach() vs. Map.keys() + Map.get()
(version: 1)
Comparing performance of:
entries() vs forEach() vs keys() + get()
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:
entries()
let allItemsMatch = true; for (const [item, count] of LIST_CACHE) { if (!inventoryMock.has(item, count)) { allItemsMatch = false; break; } }
forEach()
let allItemsMatch = true; LIST_CACHE.forEach((count, item) => { if (!allItemsMatch) return; if (!inventoryMock.has(item, count)) { allItemsMatch = false; } });
keys() + get()
let allItemsMatch = true; for (const item of LIST_CACHE.keys()) { if (!inventoryMock.has(item, LIST_CACHE.get(item))) { allItemsMatch = false; break; } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
entries()
forEach()
keys() + get()
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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36
Browser/OS:
Chrome 149 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
entries()
2734187.2 Ops/sec
forEach()
2446898.0 Ops/sec
keys() + get()
2391339.0 Ops/sec
Comments
Confirm delete:
Do you really want to delete benchmark?