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 |
Push for without cache | const vertices = [];
for (let i = 0; i < rooms.length; i++) {
const walls = rooms[i].walls;
for (let j = 0; j < walls.length; j++) {
const verts = walls[j].vertices;
for (let k = 0; k < verts.length; k++) {
vertices.push(verts[k]);
}
}
}
| ready |
Push for with cache | const vertices = [];
for (let i = 0; i < rooms.length; i++) {
const walls = rooms[i].walls;
const wallsLength = walls.length;
for (let j = 0; j < wallsLength; j++) {
const verts = walls[j].vertices;
const vertsLength = verts.length;
for (let k = 0; k < vertsLength; k++) {
vertices.push(verts[k]);
}
}
}
| ready |
Push for v2 | const vertices = [];
const roomsLength = rooms.length;
for (let i = 0; i < rooms.length; i++) {
const room = rooms[i];
for (let j = 0; j < room.walls.length; j++) {
const wall = room.walls[j];
for (let k = 0; k < wall.vertices.length; k++) {
vertices.push(wall.vertices[k]);
}
}
}
| ready |