Reduce (Slowest) | const vertices = rooms.reduce((acc, room) => {
return room.walls.reduce((acc2, wall) => {
acc2.push(...wall.vertices);
return acc2;
}, []);
}, []);
| ready |
FlatMap | const vertices = rooms.flatMap((room) => room.walls.flatMap((wall) => wall.vertices));
| ready |
Push everyone | const vertices = [];
rooms.forEach((room) => {
room.walls.forEach((wall) => {
wall.vertices.forEach((vertex) => {
vertices.push(vertex);
});
});
});
| ready |
Push spread | const vertices = [];
rooms.forEach((room) => {
room.walls.forEach((wall) => {
vertices.push(...wall.vertices)
});
});
| ready |
Push for | const vertices = [];
const roomsLength = rooms.length;
for (let i = 0; i < roomsLength; i++) {
const room = rooms[i];
const wallsLength = room.walls.length;
for (let j = 0; j < wallsLength; j++) {
const wall = room.walls[j];
const verticesLength = wall.vertices.length;
for (let k = 0; k < verticesLength; k++) {
vertices.push(wall.vertices[k]);
}
}
}
| ready |
Set for with preallocation | let requiredCount = 0;
const roomsLength = rooms.length;
for (let i = 0; i < roomsLength; i++) {
const room = rooms[i];
const wallsLength = room.walls.length;
for (let j = 0; j < wallsLength; j++) {
requiredCount += room.walls[j].vertices.length;
}
}
const vertices = new Array(requiredCount);
for (let i = 0, s = 0; i < roomsLength; i++) {
const room = rooms[i];
const wallsLength = room.walls.length;
for (let j = 0; j < wallsLength; j++) {
const wall = room.walls[j];
const verticesLength = wall.vertices.length;
for (let k = 0; k < verticesLength; k++, s++) {
vertices[s] = wall.vertices[k];
}
}
}
| ready |
Direct set without push | const vertices = [];
const roomsLength = rooms.length;
for (let i = 0, s = 0; i < roomsLength; i++) {
const room = rooms[i];
const wallsLength = room.walls.length;
for (let j = 0; j < wallsLength; j++) {
const wall = room.walls[j];
const verticesLength = wall.vertices.length;
for (let k = 0; k < verticesLength; k++, s++) {
vertices[s] = wall.vertices[k];
}
}
}
| ready |
Array-like object set | const vertices = {};
const roomsLength = rooms.length;
for (let i = 0, s = 0; i < roomsLength; i++) {
const room = rooms[i];
const wallsLength = room.walls.length;
for (let j = 0; j < wallsLength; j++) {
const wall = room.walls[j];
const verticesLength = wall.vertices.length;
for (let k = 0; k < verticesLength; k++, s++) {
vertices[s] = wall.vertices[k];
}
}
}
| ready |
Fixed vertex count push | const vertices = [];
const roomsLength = rooms.length;
for (let i = 0; i < roomsLength; i++) {
const room = rooms[i];
const wallsLength = room.walls.length;
for (let j = 0; j < wallsLength; j++) {
const wall = room.walls[j];
vertices.push(wall.vertices[0], wall.vertices[1]);
}
}
| ready |