Reduce callbacks immutability: Object accumulator (v8)

Revision 8 of this benchmark created on


Setup

const size = 6;
const data = new Array(size);
for (i=0; i<size; i++) data[i] = i;

Test runner

Ready to run.

Testing in
TestOps/sec
Mutability
var result = data.reduce(
	(accumulator, item, index) => {
		const key = 'a' + index;
		accumulator[key] = item;
		return accumulator;
	},
	{}
);
ready
Immutability
var result = data.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.