spread vs push

Benchmark created on


Setup

const arr = [];

for (let i = 0; i < 1000; i++) {
	arr.push({
		id: Math.floor(Math.random()*100),
		gid: Math.floor(Math.random()*100),
	})
}

Test runner

Ready to run.

Testing in
TestOps/sec
spread
return arr.reduce((acc, el) => {
	if (el.id < 50) {
		return acc
	}
	return [...acc, el.id]
}, [])
ready
push
return arr.reduce((acc, el) => {
	if (el.id >= 50) {
		acc.push(el.id)
	}
	return acc;
}, [])
ready
map-reduce
return arr.map(el => el.id).filter(el => el.id >= 50)
ready

Revisions

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