Spread VS Mutable

Benchmark created on


Setup

const input =
	new Array(10000)
		.fill(null)
		.map((_, index) => ({
			id: index.toString(),
			a: 1,
			b: 2,
		}));

Test runner

Ready to run.

Testing in
TestOps/sec
Spread
const output = input.reduce((acc, item) => ({
	...acc,
	[item.id]: item,
}));

ready
Mutable
const output = {};
input.forEach((item) => {
	output[item.id] = item;
});

ready

Revisions

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