From 657fba790525377b0155779d4d000fc3a63a51b8 Mon Sep 17 00:00:00 2001 From: xiange Date: Tue, 23 Jul 2024 19:48:50 +0800 Subject: [PATCH] feat(command): add performance test --- .../chili-core/src/command/commandKeys.ts | 1 + packages/chili-core/src/i18n/en.ts | 1 + packages/chili-core/src/i18n/keys.ts | 1 + packages/chili-core/src/i18n/zh-cn.ts | 1 + packages/chili-ui/src/profile/ribbon.ts | 2 +- .../chili/src/commands/application/index.ts | 1 + .../commands/application/performanceTest.ts | 69 +++++++++++++++++++ 7 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 packages/chili/src/commands/application/performanceTest.ts diff --git a/packages/chili-core/src/command/commandKeys.ts b/packages/chili-core/src/command/commandKeys.ts index 50abe1e7..fea1dddd 100644 --- a/packages/chili-core/src/command/commandKeys.ts +++ b/packages/chili-core/src/command/commandKeys.ts @@ -42,6 +42,7 @@ const COMMAND_KEYS = [ "special.last", "workingPlane.alignToPlane", "workingPlane.set", + "test.performace", ] as const; export type CommandKeys = (typeof COMMAND_KEYS)[number]; diff --git a/packages/chili-core/src/i18n/en.ts b/packages/chili-core/src/i18n/en.ts index 2d2ba6d3..d4bf29a5 100644 --- a/packages/chili-core/src/i18n/en.ts +++ b/packages/chili-core/src/i18n/en.ts @@ -167,5 +167,6 @@ export default { "vertex.point": "Point", "workingPlane.alignToPlane": "Align to plane", "workingPlane.set": "Set workplane", + "test.performace": "Performace test", }, } satisfies Locale; diff --git a/packages/chili-core/src/i18n/keys.ts b/packages/chili-core/src/i18n/keys.ts index 618f9c85..f0639b76 100644 --- a/packages/chili-core/src/i18n/keys.ts +++ b/packages/chili-core/src/i18n/keys.ts @@ -161,6 +161,7 @@ const I18N_KEYS = [ "vertex.point", "workingPlane.alignToPlane", "workingPlane.set", + "test.performace", ] as const; export type I18nKeys = (typeof I18N_KEYS)[number]; diff --git a/packages/chili-core/src/i18n/zh-cn.ts b/packages/chili-core/src/i18n/zh-cn.ts index 9f5f74bc..eb664f67 100644 --- a/packages/chili-core/src/i18n/zh-cn.ts +++ b/packages/chili-core/src/i18n/zh-cn.ts @@ -166,5 +166,6 @@ export default { "vertex.point": "点", "workingPlane.alignToPlane": "对齐到平面", "workingPlane.set": "设置工作平面", + "test.performace": "性能测试", }, } satisfies Locale; diff --git a/packages/chili-ui/src/profile/ribbon.ts b/packages/chili-ui/src/profile/ribbon.ts index e9ba9454..6546b345 100644 --- a/packages/chili-ui/src/profile/ribbon.ts +++ b/packages/chili-ui/src/profile/ribbon.ts @@ -76,7 +76,7 @@ export const DefaultRibbon: RibbonTabProfile[] = [ }, { groupName: "ribbon.group.draw", - items: ["create.line", "create.rect", ["create.circle", "create.box"]], + items: ["test.performace", "create.rect", ["create.circle", "create.box"]], }, ], }, diff --git a/packages/chili/src/commands/application/index.ts b/packages/chili/src/commands/application/index.ts index e9ea1de0..4b2ad05d 100644 --- a/packages/chili/src/commands/application/index.ts +++ b/packages/chili/src/commands/application/index.ts @@ -2,5 +2,6 @@ export * from "./newDocument"; export * from "./openDocument"; +export * from "./performanceTest"; export * from "./saveDocument"; export * from "./toFile"; diff --git a/packages/chili/src/commands/application/performanceTest.ts b/packages/chili/src/commands/application/performanceTest.ts new file mode 100644 index 00000000..ab1b3bfb --- /dev/null +++ b/packages/chili/src/commands/application/performanceTest.ts @@ -0,0 +1,69 @@ +import { + EditableGeometryEntity, + GeometryModel, + IApplication, + ICommand, + IDocument, + Material, + Plane, + XYZ, + command, +} from "chili-core"; + +export abstract class PerformanceTestCommand implements ICommand { + protected size = 10; + protected gap = 1; + protected rowCols = 20; + + async execute(app: IApplication): Promise { + let document = await app.newDocument("OCC Performace Test"); + let lightGray = new Material(document, "LightGray", 0xdedede); + let deepGray = new Material(document, "DeepGray", 0x898989); + document.materials.push(lightGray, deepGray); + + const start = Date.now(); + const distance = this.gap + this.size; + for (let x = 0; x < this.rowCols; x++) { + for (let y = 0; y < this.rowCols; y++) { + for (let z = 0; z < this.rowCols; z++) { + let position = XYZ.zero + .add(XYZ.unitX.multiply(x * distance)) + .add(XYZ.unitY.multiply(y * distance)) + .add(XYZ.unitZ.multiply(z * distance)); + this.createShape(document, lightGray, position); + } + } + } + console.log( + `Create ${this.rowCols * this.rowCols * this.rowCols} shapes, Time: ${Date.now() - start} ms`, + ); + } + + protected abstract createShape(document: IDocument, material: Material, position: XYZ): void; +} + +@command({ + name: "test.performace", + display: "test.performace", + icon: "", +}) +export class OccPerformanceTestCommand extends PerformanceTestCommand { + private index = 1; + + protected override createShape(document: IDocument, material: Material, position: XYZ): void { + let plane = Plane.XY.translateTo(position); + let box = document.application.shapeFactory.box( + plane, + this.size * Math.random(), + this.size * Math.random(), + this.size * Math.random(), + ); + let entity = new EditableGeometryEntity(document, box.unwrap(), material.id); + let model = new GeometryModel(document, `box ${this.index++}`, entity); + document.addNode(model); + } +} + +// export class ThreePerformanceTestCommand extends PerformanceTestCommand { + +// }