For of vs Map.forEach (v2)

Revision 2 of this benchmark created on


Setup

let vals = new Map();

function rndm() { return Math.round(Math.random()*1000);
}

function doSomething() {
	let internal
	
	internal = rndm()
	
	return internal
}

for (let i = 0; i < 1000; i++) {
  	const rnd = rndm()
    vals.set(`item${i}`, rnd);
}

Test runner

Ready to run.

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

Revisions

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