From 3dba3c2b3997d889d840b27e8c2937b9535db98a Mon Sep 17 00:00:00 2001 From: Max Richter Date: Fri, 24 Apr 2026 21:35:33 +0200 Subject: [PATCH] feat: count total-vertices and faces in benchmark --- app/benchmark/index.ts | 28 ++++++++++++++++++++++++++-- packages/utils/src/performance.ts | 9 +++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/app/benchmark/index.ts b/app/benchmark/index.ts index beec3ea..a152d3c 100644 --- a/app/benchmark/index.ts +++ b/app/benchmark/index.ts @@ -1,5 +1,5 @@ import type { Graph, Graph as GraphType, NodeId } from '@nodarium/types'; -import { createLogger, createPerformanceStore } from '@nodarium/utils'; +import { createLogger, createPerformanceStore, splitNestedArray } from '@nodarium/utils'; import { mkdir, writeFile } from 'node:fs/promises'; import { resolve } from 'node:path'; import { MemoryRuntimeExecutor } from '../src/lib/runtime/runtime-executor.ts'; @@ -20,6 +20,26 @@ const templates: Record = { 'default': defaultPlantTemplate as unknown as GraphType }; +function countGeometry(result: Int32Array): { totalVertices: number; totalFaces: number } { + const parts = splitNestedArray(result); + let totalVertices = 0; + let totalFaces = 0; + for (const part of parts) { + const type = part[0]; + const vertexCount = part[1]; + const faceCount = part[2]; + if (type === 2) { + const instanceCount = part[3]; + totalVertices += vertexCount * instanceCount; + totalFaces += faceCount * instanceCount; + } else { + totalVertices += vertexCount; + totalFaces += faceCount; + } + } + return { totalVertices, totalFaces }; +} + async function run(g: GraphType, amount: number) { await registry.load(plantTemplate.nodes.map(n => n.type) as NodeId[]); log.log('loaded ' + g.nodes.length + ' nodes'); @@ -33,10 +53,14 @@ async function run(g: GraphType, amount: number) { log.log('executing'); r.perf = perfStore; + let res; for (let i = 0; i < amount; i++) { r.perf?.startRun(); - await r.execute(g, { randomSeed: true }); + res = await r.execute(g, { randomSeed: true }); r.perf?.stopRun(); + const { totalVertices, totalFaces } = countGeometry(res!); + r.perf?.addToLastRun('total-vertices', totalVertices); + r.perf?.addToLastRun('total-faces', totalFaces); } log.log('finished'); return r.perf.get(); diff --git a/packages/utils/src/performance.ts b/packages/utils/src/performance.ts index f9335b0..439b6fd 100644 --- a/packages/utils/src/performance.ts +++ b/packages/utils/src/performance.ts @@ -4,6 +4,7 @@ export interface PerformanceStore { startRun(): void; stopRun(): void; addPoint(name: string, value?: number): void; + addToLastRun(name: string, value: number): void; endPoint(name?: string): void; mergeData(data: PerformanceData[number]): void; get: () => PerformanceData; @@ -63,6 +64,13 @@ export function createPerformanceStore(): PerformanceStore { } } + function addToLastRun(name: string, value: number) { + const last = data[data.length - 1]; + if (!last) return; + last[name] = last[name] || []; + last[name].push(value); + } + function get() { return data; } @@ -94,6 +102,7 @@ export function createPerformanceStore(): PerformanceStore { startRun, stopRun, addPoint, + addToLastRun, endPoint, mergeData, get