Skip to content

Commit 9e631b0

Browse files
committed
chore: add performance test
Related to #96
1 parent cb7abf8 commit 9e631b0

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

test/spec/MinimapSpec.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,97 @@ describe('minimap', function() {
258258
expectMinimapShapeToExist('child');
259259
}));
260260

261+
262+
// only use in isolation performance testing, this isn't a proper test and shouldn't run on CI
263+
it.only('performance test', inject(function(canvas, modeling, elementFactory, minimap) {
264+
265+
const GRID_MATRIX = [
266+
[ 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4 ],
267+
[ 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4 ],
268+
[ 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4 ],
269+
[ 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4 ],
270+
[ 4,4,4,4,4,4,4,4,4,4,4,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4 ],
271+
[ 4,4,4,4,4,4,4,4,4,4,4,2,0,0,0,0,0,2,4,4,4,4,4,4,4,4,4,4,4,4 ],
272+
[ 4,4,4,4,4,4,4,4,4,4,4,2,1,1,1,1,1,0,3,4,4,4,4,4,4,4,4,4,4,4 ],
273+
[ 4,4,4,4,4,4,4,4,4,4,4,2,0,1,4,4,1,1,2,4,4,4,4,4,4,4,4,4,4,4 ],
274+
[ 4,4,4,4,4,4,4,4,4,4,4,2,0,1,4,4,1,0,2,4,4,4,4,4,4,4,4,4,4,4 ],
275+
[ 4,4,4,4,4,4,4,4,4,4,4,2,0,1,4,4,1,0,2,4,4,4,4,4,4,4,4,4,4,4 ],
276+
[ 4,4,4,4,4,4,4,4,4,4,4,2,0,1,3,2,1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3,2,2,2,2,2,2,3,4,4,4,4,4,4,4,4,4,4,4 ],
292+
[ 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4 ],
293+
[ 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4 ],
294+
[ 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4 ],
295+
[ 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4 ]
296+
];
297+
298+
const root = canvas.getRootElement();
299+
const CELL = 40;
300+
const GAP = 4;
301+
const CHUNK = 150;
302+
303+
const tasks = [];
304+
305+
GRID_MATRIX.forEach((row, rIdx) => {
306+
row.forEach((layers, cIdx) => {
307+
for (let l = 0; l < layers; l++) {
308+
const shrink = l * GAP;
309+
const size = CELL - shrink * 2;
310+
if (size <= 4) continue;
311+
tasks.push({
312+
id: `grid_${rIdx}_${cIdx}_${l}`,
313+
x: cIdx * CELL + shrink,
314+
y: rIdx * CELL + shrink,
315+
width: size,
316+
height: size
317+
});
318+
}
319+
});
320+
});
321+
322+
let index = 0;
323+
324+
function processChunk() {
325+
const end = Math.min(index + CHUNK, tasks.length);
326+
327+
for (; index < end; index++) {
328+
const t = tasks[index];
329+
const shape = elementFactory.createShape({
330+
id: t.id,
331+
x: t.x,
332+
y: t.y,
333+
width: t.width,
334+
height: t.height
335+
});
336+
modeling.createShape(shape, { x: shape.x, y: shape.y }, root);
337+
}
338+
339+
if (index < tasks.length) {
340+
requestAnimationFrame(processChunk);
341+
} else {
342+
343+
setTimeout(() => {
344+
minimap._update();
345+
}, 100);
346+
}
347+
}
348+
349+
requestAnimationFrame(processChunk);
350+
}));
351+
261352
});
262353

263354

0 commit comments

Comments
 (0)