Reduce callbacks immutability: Array accumulator

Benchmark created on


Setup

const maxPower = 5;  
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) => {
			accumulator.push(item);
			return accumulator;
		},
		[]
	);
}

ready
Immutability
for (i=0; i<=maxPower; i++) {
	var result = data[i].reduce(
		(accumulator, item, index) => {
			return [...accumulator, item];
		},
		[]
	);
}
ready

Revisions

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