feat: count total-vertices and faces in benchmark
Some checks failed
📊 Benchmark the Runtime / release (pull_request) Failing after 1m21s
🚀 Lint & Test & Deploy / release (pull_request) Failing after 56s

This commit is contained in:
2026-04-24 21:35:33 +02:00
parent 09a9f8ce2c
commit 3dba3c2b39
2 changed files with 35 additions and 2 deletions

View File

@@ -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<string, Graph> = {
'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();