Skip to content

Commit

Permalink
feat(command): add performance test
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangechen committed Jul 23, 2024
1 parent c0abc15 commit 657fba7
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/chili-core/src/command/commandKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const COMMAND_KEYS = [
"special.last",
"workingPlane.alignToPlane",
"workingPlane.set",
"test.performace",
] as const;

export type CommandKeys = (typeof COMMAND_KEYS)[number];
1 change: 1 addition & 0 deletions packages/chili-core/src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,6 @@ export default {
"vertex.point": "Point",
"workingPlane.alignToPlane": "Align to plane",
"workingPlane.set": "Set workplane",
"test.performace": "Performace test",
},
} satisfies Locale;
1 change: 1 addition & 0 deletions packages/chili-core/src/i18n/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ const I18N_KEYS = [
"vertex.point",
"workingPlane.alignToPlane",
"workingPlane.set",
"test.performace",
] as const;

export type I18nKeys = (typeof I18N_KEYS)[number];
1 change: 1 addition & 0 deletions packages/chili-core/src/i18n/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,6 @@ export default {
"vertex.point": "点",
"workingPlane.alignToPlane": "对齐到平面",
"workingPlane.set": "设置工作平面",
"test.performace": "性能测试",
},
} satisfies Locale;
2 changes: 1 addition & 1 deletion packages/chili-ui/src/profile/ribbon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]],
},
],
},
Expand Down
1 change: 1 addition & 0 deletions packages/chili/src/commands/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

export * from "./newDocument";
export * from "./openDocument";
export * from "./performanceTest";
export * from "./saveDocument";
export * from "./toFile";
69 changes: 69 additions & 0 deletions packages/chili/src/commands/application/performanceTest.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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 {

// }

0 comments on commit 657fba7

Please sign in to comment.