Reduce - mutate vs new object

Benchmark created on


Setup

const values = new Array(1_000).fill(true).map(v => Math.random())

Test runner

Ready to run.

Testing in
TestOps/sec
Mutate
values.reduce((acc, cur) => {
	acc[cur] = true; 
	return acc; 
})
ready
New Object
values.reduce((acc, cur) => {
	return {
		...acc, 
		[cur]: true
	}
})
ready

Revisions

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