Array push vs Array map

Benchmark created on


Setup

const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]

Test runner

Ready to run.

Testing in
TestOps/sec
Array push
const temp = []
array.forEach(i => {
	const newI = i ** 2
	temp.push(newI)
})
ready
Array map
const temp = array.map(i => {
	const newI = i ** 2
	return newI
})
ready

Revisions

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