spreading vs looping

Benchmark created on


Setup

const objectsA = new Array(10000).fill({a:1});
const objectsB = new Array(10000).fill({a:1});

Test runner

Ready to run.

Testing in
TestOps/sec
Spread
const spread = [...objectsA, ...objectsB];
const max = Math.max(...spread.map(object => object.a + 1));
ready
Looping (Greedy Algorithm)
let max = -Infinity;
for (let array of [objectsA, objectsB]) {
	for (let object of array) {
		max = Math.max(max, object.a + 1);
	}
}
ready

Revisions

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