Reduce spread vs mutate

Benchmark created on


Setup

const data = Array.from({ length: 1000 }).map(() => ({ value: Math.random()}))

Test runner

Ready to run.

Testing in
TestOps/sec
Spread
const mappedSpread = data.reduce((acc, d, idx) => ({
	...acc,
	[d.value]: idx
}))
ready
Mutate
const mappedMutate = data.reduce((acc, d, idx) => {
	acc[d.value] = idx
	return acc;
})
ready

Revisions

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