Reduce callbacks immutability: Object accumulator

Benchmark created on


Setup

const maxPower = 4;  
const data = new Array(maxPower+1);
for(i=0; i<=maxPower; i++) {
	const size = 10 ** i;
	const arrI = new Array(size);
	for (j=0; j<size; j++) arrI[j] = j;

	data[i] = arrI;
};

Test runner

Ready to run.

Testing in
TestOps/sec
Mutability
for (i=0; i<=maxPower; i++) {
	var result = data[i].reduce(
		(accumulator, item, index) => {
			const key = 'a' + index;
			accumulator[key] = item;
			return accumulator;
		},
		{}
	);
}
ready
Immutability
for (i=0; i<=maxPower; i++) {
	var result = data[i].reduce(
		(accumulator, item, index) => {
			const key = 'a' + index;
			return {
				...accumulator,
				[key]: item,
			};
		},
		{}
	);
}
ready

Revisions

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