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

Revision 4 of this benchmark created on


Setup

const power = 3;  
const size = 10 ** power;
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 = data.reduce(
	(accumulator, item, index) => {
		accumulator[index] = item;
		return accumulator;
	},
	new Array(data.length)
);
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.