feat: count total-vertices and faces in benchmark
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import type { Graph, Graph as GraphType, NodeId } from '@nodarium/types';
|
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 { mkdir, writeFile } from 'node:fs/promises';
|
||||||
import { resolve } from 'node:path';
|
import { resolve } from 'node:path';
|
||||||
import { MemoryRuntimeExecutor } from '../src/lib/runtime/runtime-executor.ts';
|
import { MemoryRuntimeExecutor } from '../src/lib/runtime/runtime-executor.ts';
|
||||||
@@ -20,6 +20,26 @@ const templates: Record<string, Graph> = {
|
|||||||
'default': defaultPlantTemplate as unknown as GraphType
|
'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) {
|
async function run(g: GraphType, amount: number) {
|
||||||
await registry.load(plantTemplate.nodes.map(n => n.type) as NodeId[]);
|
await registry.load(plantTemplate.nodes.map(n => n.type) as NodeId[]);
|
||||||
log.log('loaded ' + g.nodes.length + ' nodes');
|
log.log('loaded ' + g.nodes.length + ' nodes');
|
||||||
@@ -33,10 +53,14 @@ async function run(g: GraphType, amount: number) {
|
|||||||
|
|
||||||
log.log('executing');
|
log.log('executing');
|
||||||
r.perf = perfStore;
|
r.perf = perfStore;
|
||||||
|
let res;
|
||||||
for (let i = 0; i < amount; i++) {
|
for (let i = 0; i < amount; i++) {
|
||||||
r.perf?.startRun();
|
r.perf?.startRun();
|
||||||
await r.execute(g, { randomSeed: true });
|
res = await r.execute(g, { randomSeed: true });
|
||||||
r.perf?.stopRun();
|
r.perf?.stopRun();
|
||||||
|
const { totalVertices, totalFaces } = countGeometry(res!);
|
||||||
|
r.perf?.addToLastRun('total-vertices', totalVertices);
|
||||||
|
r.perf?.addToLastRun('total-faces', totalFaces);
|
||||||
}
|
}
|
||||||
log.log('finished');
|
log.log('finished');
|
||||||
return r.perf.get();
|
return r.perf.get();
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ export interface PerformanceStore {
|
|||||||
startRun(): void;
|
startRun(): void;
|
||||||
stopRun(): void;
|
stopRun(): void;
|
||||||
addPoint(name: string, value?: number): void;
|
addPoint(name: string, value?: number): void;
|
||||||
|
addToLastRun(name: string, value: number): void;
|
||||||
endPoint(name?: string): void;
|
endPoint(name?: string): void;
|
||||||
mergeData(data: PerformanceData[number]): void;
|
mergeData(data: PerformanceData[number]): void;
|
||||||
get: () => PerformanceData;
|
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() {
|
function get() {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@@ -94,6 +102,7 @@ export function createPerformanceStore(): PerformanceStore {
|
|||||||
startRun,
|
startRun,
|
||||||
stopRun,
|
stopRun,
|
||||||
addPoint,
|
addPoint,
|
||||||
|
addToLastRun,
|
||||||
endPoint,
|
endPoint,
|
||||||
mergeData,
|
mergeData,
|
||||||
get
|
get
|
||||||
|
|||||||
Reference in New Issue
Block a user