Reduce with spread vs for of with array push

Benchmark created on


Setup

function setupDataArray(numOfIterations) {
	const data = [];
	for (let i = 0; i < numOfIterations; i++) {
		data.push(i);
	}
	return data;
}

const iters = 100000

Test runner

Ready to run.

Testing in
TestOps/sec
Reduce with spread
setupDataArray(iters).reduce((acc, point) => acc = [...acc, point], []);
ready
array.push within for-of loop
const data = setupDataArray(iters);
const acc = [];
for (point of data) {
	acc.push(point);
}
ready
For loop with array.push
const data = setupDataArray(iters);
const acc = [];
for (let i = 0; i < data.length; i++) {
	acc.push(data[i]);
}
ready

Revisions

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