Skip to content

Commit

Permalink
test: add base perf test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Aarebecca committed Oct 16, 2024
1 parent 2c3ed24 commit 62d7c8a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions __tests__/demos/perf/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { circles } from './circles';
export { rects } from './rect';
47 changes: 47 additions & 0 deletions __tests__/demos/perf/rect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Rect, Group, runtime } from '@antv/g';
import type { Canvas } from '@antv/g';

runtime.enableCSSParsing = false;

export async function rects(context: { canvas: Canvas }) {
const { canvas } = context;

await canvas.ready;

const group1 = new Group({});
const group2 = group1.appendChild(new Group({}));
canvas.appendChild(group2);

console.time('render');

for (let i = 0; i < 10_0000; i++) {
const group = new Group({
style: {
// transform: [['translate', Math.random() * 640, Math.random() * 640]],
transform: `translate(${Math.random() * 640}, ${Math.random() * 640})`,
},
});

group.appendChild(
new Rect({
style: {
width: 10,
height: 10,
fill: '#1890FF',
stroke: '#F04864',
lineWidth: 4,
},
}),
);

group2.appendChild(group);
}

canvas.addEventListener(
'rerender',
() => {
console.timeEnd('render');
},
{ once: true },
);
}

0 comments on commit 62d7c8a

Please sign in to comment.