Files
DOSSIER/src/plan/sectionBench.test.ts
T
Claude c59619d1fc [K3c] Schnitt und Ansicht im Kern: Abfragen sectionPlan/elevationPlan liefern den Plan-Puffer v2
Neu: core/src/plan/section.rs (toSection.ts, generateSectionPlan, sectionOpenings.ts) und
core/src/plan/elevation.rs (toElevation.ts) rechnen auf dem Projekt-Dokument: Besitzer-Zuordnung,
Schicht-Bänder, Stil, Decken-Terminierung, Dominanz, Treppen, Monolith, Abzugskörper, Körper,
Gelände, Schnitt-Tiefe, geschnittene Fenster/Türen; Ansicht mit Eck-Verlängerung, Verdeckung,
Schatten und Painter-Reihenfolge. Der Prismen-Schnitt läuft über render3d::section::cut_section
(Kern hängt an render3d ohne Features); die frühere JSON-Reise der Zahlen wird bitgleich
nachgebildet. Aus TS kommen nur die truck-Körper (Float64Array). Die TS-Fassade
(plan/sectionCore.ts) liefert lazy Pläne wie generatePlan; Viewport, CLI und MCP laufen darüber.
CLI section/elevation kann --format json (render2d-Szene).

Gleichheit (vorübergehender Test sectionPort.parity.test.ts): Primitive (Object.is), Ausmass,
Szene und SVG gegen die TS-Fassung — Beispiel, 60 Zufallsprojekte, Kacheln 6x6; CLI-SVG
byte-gleich. Ausnahme: durchgesickerte render3d-Schraffur nicht zuordenbarer Bänder wird zur
vorgesehenen Rückfall-Schraffur (s. TODO). Die alte TS-Fassung bleibt bis nach den
Leistungs-Schritten für den Vergleich stehen. Nicht in der Tauri-App angesehen.
2026-10-29 04:17:22 +00:00

67 lines
3.6 KiB
TypeScript

// VORÜBERGEHEND ([K3c]): Messung alt (TS) gegen neu (Kern) für Schnitt und Ansicht (nur mit BENCH=1).
import { it } from "vitest";
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { setWasmBytesProvider } from "../engine/wasmSource";
import { computeSection as oldCompute } from "./toSection";
import { generateSectionPlan as oldGen } from "./generatePlan";
import { sectionOpeningPrimitives } from "./sectionOpenings";
import { generateElevationPlan as oldElev } from "./toElevation";
import { computeSection as newCompute, generateSectionPlan as newGen, generateElevationPlan as newElev } from "./sectionCore";
import { planToRenderScene } from "./toRenderScene";
import { sampleProject } from "../model/sampleProject";
import { flattenCategories } from "../model/types";
import type { DrawingLevel, Project } from "../model/types";
import { bigSectionProject } from "./sectionParity.testing";
async function time(f: () => Promise<unknown> | unknown, runs: number): Promise<[number, number]> {
await f();
const t: number[] = [];
for (let i = 0; i < runs; i++) {
const t0 = performance.now();
await f();
t.push(performance.now() - t0);
}
t.sort((a, b) => a - b);
return [t[0], t[Math.floor(t.length / 2)]];
}
const fmt = ([a, b]: [number, number]) => `${a.toFixed(1)}/${b.toFixed(1)}`;
it.skipIf(!process.env.BENCH)("Messung Schnitt/Ansicht alt gegen neu", async () => {
setWasmBytesProvider(async (name) => readFileSync(join(process.cwd(), "src", "engine", name === "trucksolid" ? "pkgTruck/trucksolid_bg.wasm" : "pkg3d/render3d_bg.wasm")));
const only = process.env.BENCH_ONLY;
const all: Array<[string, Project]> = [["Beispiel", sampleProject], ["big6", bigSectionProject(6)], ["big8", bigSectionProject(8)], ["big16", bigSectionProject(16)]];
const cases = all.filter(([n]) => !only || only.split(",").includes(n));
const rows: string[] = ["Projekt | Ebene | alt Plan | neu Plan | alt +Szene | neu +Szene (ms min/median)"];
for (const [name, p] of cases) {
const codes = new Set(flattenCategories(p.layers).map((c) => c.code));
const levels = p.drawingLevels.filter((l) => (l.kind === "section" || l.kind === "elevation") && l.linePoints) as DrawingLevel[];
const runs = name === "big16" ? 1 : name === "Beispiel" ? 20 : 5;
for (const l of levels) {
if (l.kind === "section") {
const oldP = async () => {
const o = (await oldCompute(p, l))!;
const pl = oldGen(o, false, { hiddenLines: l.hiddenLines, visibleCodes: codes });
return { ...pl, primitives: [...pl.primitives, ...sectionOpeningPrimitives(p, l, codes)] };
};
const newP = async () => newGen((await newCompute(p, l))!, false, { hiddenLines: l.hiddenLines, visibleCodes: codes, openings: true });
const a = await time(oldP, runs);
const b = await time(newP, runs);
const c = await time(async () => planToRenderScene(await oldP(), 100), runs);
const d = await time(async () => planToRenderScene(await newP(), 100), runs);
rows.push(`${name} | ${l.id} Schnitt | ${fmt(a)} | ${fmt(b)} | ${fmt(c)} | ${fmt(d)}`);
process.stderr.write(rows[rows.length - 1] + "\n");
} else {
const a = await time(() => oldElev(p, l), runs);
const b = await time(() => newElev(p, l), runs);
const c = await time(() => planToRenderScene(oldElev(p, l)!, 100), runs);
const d = await time(() => planToRenderScene(newElev(p, l)!, 100), runs);
rows.push(`${name} | ${l.id} Ansicht | ${fmt(a)} | ${fmt(b)} | ${fmt(c)} | ${fmt(d)}`);
process.stderr.write(rows[rows.length - 1] + "\n");
}
}
}
console.log(rows.join("\n"));
}, 3_600_000);