For of vs Map.forEach

Benchmark created on


Setup

let vals = new Map();
for (let i = 0; i < 1000; i++) {
  	const rnd = Math.round(Math.random()*1000);
    vals.set(`item${i}`, rnd);
}

Test runner

Ready to run.

Testing in
TestOps/sec
For of
for (const val of vals.values()) {
	let newVal = val + val
}
ready
Map.forEach
vals.forEach((val) => {
	let newVal = val + val
})
ready

Revisions

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