map vs array iteration

Benchmark created on


Setup

const arr = [];
const map = new Map();
for (let i = 0; i < 100; i++){
	console.log(i);
	arr.push(i);
	map.set(i, i);
}

Test runner

Ready to run.

Testing in
TestOps/sec
array
return arr.map(num => num*3);
ready
map
return Array.from(map.values()).map(num => num*3)
ready
map, .map first before array conversion
return Array.from(map.values().map(num => num*3))
ready

Revisions

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