Reduce callbacks immutability: Pre-allocated array accumulator (v14)

Revision 14 of this benchmark created on


Setup

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

Test runner

Ready to run.

Testing in
TestOps/sec
With pre-allocation
var result = new Array(data.length);
for(j=0; j<result.length; j++) {
	result[j] = -1;
}
result = data.reduce(
	(accumulator, item, index) => {
		accumulator[index] = item;
		return accumulator;
	},
	result
);
ready
Without pre-allocation
var result = data.reduce(
	(accumulator, item, index) => {
		accumulator.push(item);
		return accumulator;
	},
	[]
);
ready

Revisions

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