Meow1

Benchmark created on


Setup

const count = 100;
const arr = new Array(count);
for (let i = 0; i < count; i++) {
  arr[i] = {
    vertices: [
      { x: Math.random() * 10, y: Math.random() * 10 },
      { x: Math.random() * 10, y: Math.random() * 10 },
	],
  };
}

Test runner

Ready to run.

Testing in
TestOps/sec
Reduce #1
const vertices = arr.reduce((acc, wall) => {
	acc.push(...wall.vertices);
	return acc;
}, []);
ready
Reduce #2
const vertices = arr.reduce((acc, wall) =>
	acc.concat(wall.vertices),
	[],
);
ready
Linear
const vertices = [];
for (let i = 0; i < count; i++) {
	vertices.push(arr[i].vertices[0], arr[i].vertices[1]);
}
ready
Super Linear preallocate
const vertices = new Array(count * 2);
for (let i = 0; i < count; i++) {
	vertices[i * 2] = arr[i].vertices[0];
	vertices[i * 2 + 1] = arr[i].vertices[1];
}
ready

Revisions

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