Performance Testing
A frame rate reading tells you how one moment went. world.measurePerformance() records every frame while an action plays out, so a test can check the 95th percentile, count the hitches, and tell you what the game was doing when each one happened.
Measuring an Action
Wrap what you want to measure in a function. Specter starts recording in the engine, runs it, stops, and returns the capture for the matchers below. The measurement shows as a Measure performance step in the report; if the action throws, the capture is still stopped and attached before the error is rethrown.
import { test, expect } from '@specter-automation/test';
test('a wave of 40 minions stays smooth', async ({ world }) => {
const perf = await world.measurePerformance(async () => {
for (let i = 0; i < 40; i++) {
await world.spawnActor('BP_Minion', { location: { x: i * 120, y: 2800, z: 100 } });
}
await world.waitForTimeout(5000);
}, { name: 'Minion wave' });
await expect(perf).toHaveFrameTimeP95Below(16.7);
await expect(perf).toHaveOnePercentLowFPSAbove(45);
await expect(perf).toHaveNoHitchesOver(50);
await expect(perf).toHaveMemoryGrowthBelow(200);
});What's Measured
- Frame time: average, p50, p90, p95, p99 and the slowest frame.
- FPS: average, 1% low (the frame rate of the slowest 1% of frames) and minimum.
- Where the time went: game thread (working and waiting), render thread, GPU, and Slate UI, each as average and p95.
- Draw calls per frame (average and peak), and memory at the start, peak, end, and its growth.
- Hitches: every frame over
hitchMs, slowest first. Each says what most of the frame went to (game thread, GPU, Slate UI…) and what happened in that frame or the one before: garbage collection, level streaming, Specter commands, test steps, and your game's timeline events.
Some stats stay at 0 on some platforms (render thread time and draw calls in the editor on Mac, for example). The capture marks those as not reported, the runner shows “—”, and matchers that need them refuse to check rather than pass on a 0.
const perf = await world.measurePerformance(action, {
name: 'Boss phase 2', // shown in the runner and in failure messages (default "performance")
hitchMs: 33, // frames slower than this count as hitches (default 50)
timelinePreview: false, // pause the timeline preview while measuring (default true)
});
perf.frameTimeMs.p95; // milliseconds
perf.fps.onePercentLow;
perf.memoryMb.growth; // MB
perf.hitches[0].events; // what happened around the slowest frameThe full shape is PerformanceCapture.
Checking a Capture
| Matcher | Passes when |
|---|---|
| toHaveFrameTimeP95Below(ms) | 95% of frames took at most this long. |
| toHaveFrameTimeP99Below(ms) | 99% of frames took at most this long. |
| toHaveAverageFrameTimeBelow(ms) | The average frame took at most this long. |
| toHaveAverageFPSAbove(fps) | It averaged at least this frame rate. |
| toHaveOnePercentLowFPSAbove(fps) | Even the slowest 1% of frames ran at least this fast. |
| toHaveNoHitchesOver(ms, { allowed? }) | No frame (or at most allowed frames) took longer than this. |
| toHavePeakMemoryBelow(mb) | Memory never went above this. |
| toHaveMemoryGrowthBelow(mb) | Memory grew by at most this from start to end. |
| toHaveDrawCallsBelow(n, { stat? }) | Draw calls per frame stayed under this, on average or at peak. |
| toMaintainPerformanceBudget(budget) | Every limit in the budget held (also works on world, sampling live). |
When one fails, the message has the summary and the slowest hitches with what happened around them, so the first lead is in the CI log:
Error: Expected the frame times of "Minion wave" to be free of frames over 50.0 ms, but it was 3 frames over 50.0 ms.
avg 9.1 ms · p95 14.2 ms · 109 fps · 3 hitches over 50.0 ms (598 frames in 5.48 s)
3 frames over 50.0 ms, slowest first:
- 112 ms at 4.20 s in the test (Game thread): Garbage collection (38.0 ms)
- 61.3 ms at 2.05 s in the test (GPU): GE Applied [GE_MinionBuff] (frame before)
- 52.8 ms at 4.71 s in the test (Game thread)In the Runner
Select the Measure performance step in the in-engine runner to see the frame-time graph, the numbers, and the list of hitches. The timeline preview keeps recording while you measure, so you can scrub to a hitch and see what was on screen. Each preview frame costs a GPU readback; pass timelinePreview: false for the strictest numbers.
Getting Numbers You Can Trust
- The editor has its own cost (its UI ticks every frame). Measure in a standalone or packaged build, as in CI, for numbers that match what players get, and compare editor runs with editor runs.
- Short captures (600 frames or fewer) keep every frame. For longer ones, set
hitchMsto the strictest limit you'll check:toHaveNoHitchesOver(33)on a capture measured with the default 50 ms asks you to. - For a quick live reading without a capture,
toHaveFPS(),toHaveMinFPS(),toHaveFrameTimeBelow()andtoHaveMemoryBelow()poll the engine's current values.