fuzzyworld

explodorama / files / test / perf.test.ts

perf.test.ts

1.4 KB · history · blame

1import { expect, it } from 'vitest'
2import { generateScene, SCENE_KINDS } from '../src/sim/demo'
3
4/**
5 * Perf budget for demo generation. Scenes are found by random play, so a scene kind whose moment
6 * is a rare chain gets slow without anything failing (CI went red on the Decoy tests' default
7 * 5 s timeout, 2026-11-01). Each seed of each kind is timed; the slowest are printed, and any seed
8 * over the budget fails here, naming the kind. The budget is several times the slowest seen
9 * (Freeze, ~1.1 s on a laptop) to leave room for a slow CI runner.
10 */
11const SEEDS = [1, 2, 3]
12const BUDGET_MS = 4000
13
14it(`every demo scene is found within ${BUDGET_MS} ms a seed`, () => {
15 const times: { kind: string; seed: number; ms: number }[] = []
16 for (const kind of SCENE_KINDS) {
17 for (const seed of SEEDS) {
18 const t = performance.now()
19 generateScene(kind, seed)
20 times.push({ kind, seed, ms: Math.round(performance.now() - t) })
21 }
22 }
23 times.sort((a, b) => b.ms - a.ms)
24 console.log('slowest demo scenes:\n' + times.slice(0, 5).map((t) => ` ${t.kind} seed ${t.seed}: ${t.ms} ms`).join('\n'))
25 const slow = times.filter((t) => t.ms > BUDGET_MS)
26 expect(slow, `over ${BUDGET_MS} ms: ${slow.map((t) => `${t.kind}#${t.seed} ${t.ms} ms`).join(', ')}`).toEqual([])
27 // Every kind runs three times, so this test as a whole is slow (~9 s here): its own timeout.
28}, 120_000)