Files
horizon/tests/test_pacing_bench.py
Ludovic MarieandClaude Opus 5.5 d5273ce67f Frame pacing benchmark: tools/pacing_bench.py, stats raw, spans::laps
perf_bench measures throughput on short flights; pacing_bench records every
frame of the sessions where players see hitches (64 blocks/s flight, eight
long teleports, Nether trips, inventory and pause menu spam) and reports p50,
p99, p99.9, max, 1% and 0.1% lows and frames over 33 ms, with the timed spans
of the slowest frames (HORIZON_SPIKES) beside them.

- horizon-ctl `stats raw`: every frame time since the last reset, as `fly ...
  raw` gives for a flight.
- spans::laps: a function's consecutive steps as spans, nothing read while
  spans are off. Renderer::draw_frame and Game::entity_geometry time their
  steps with it; they found the lead knot's model parse (41 ms) and the
  arena page frees (8-14 ms).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-02 02:50:38 +01:00

29 lines
980 B
Python

import unittest
from tools.pacing_bench import stats
class StatsTests(unittest.TestCase):
def test_lows_percentiles_and_hitch_counts(self):
# 998 frames of 5 ms, one of 40 ms and one of 100 ms.
frames = [5.0] * 998 + [40.0, 100.0]
s = stats(frames)
self.assertEqual(s["frames"], 1000)
self.assertEqual(s["p50_ms"], 5.0)
self.assertEqual(s["p99_ms"], 5.0)
self.assertEqual(s["p999_ms"], 40.0)
self.assertEqual(s["max_ms"], 100.0)
# The slowest 1% (10 frames): 8 x 5 + 40 + 100 = 180 ms, 18 ms each.
self.assertAlmostEqual(s["low_1pct_fps"], round(1000 / 18.0, 1))
# The slowest 0.1% is the single 100 ms frame.
self.assertEqual(s["low_01pct_fps"], 10.0)
self.assertEqual(s["over_33ms"], 2)
self.assertEqual(s["over_2x_median"], 2)
def test_no_frames(self):
self.assertEqual(stats([]), {"frames": 0})
if __name__ == "__main__":
unittest.main()