Map forEach vs Map for of vs Object.entries

Benchmark created on


Setup

const obj = {
    1: "ASDASDASDASD",
    2: "ASDASDASDASDASDA",
    3: "ASDASDASDASDAAA",
    4: 5242,
    5: "AAAAAA",
    6: "asdasdasdasd",
    7: [24342343, "sweet", "hello"],
    8: [1, 2, 3, 4],
    9: [1, 2, 3, 4, 5],
    10: "AAA",
    11: 5545,
    12: "gutenTag"
}
const map = new Map(Object.entries(obj))

Test runner

Ready to run.

Testing in
TestOps/sec
Map for of
for (const [k, v] of map){
    console.log(k, v)
}
ready
Map for each
map.forEach((k, v) => {
	console.log(k, v)
})
ready
Object.entries
for (const [k, v] of Object.entries(obj)){
    console.log(k, v)
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.