b691b5ebaa
tools/perf_bench.py runs Horizon, the vanilla 26.3 client and vanilla with Sodium, Lithium, FerriteCore and ImmediatelyFast through the same steps: fresh world (seed 1234, creative) per render distance, start to title, start to in-world, then per scene teleport, chunk load, settle and a fixed 192-block flight. Every frame time is kept and one function computes average FPS, 1% and 0.1% lows, p50/p95/p99/p99.9 and a frame-time histogram for every game; RSS is sampled from outside the process for every game. One options.txt (vanilla's keys, Fancy preset values with a Custom preset so the render distance holds) is written for all of them. Vanilla is driven by a dev-only Fabric mod (mods/horizon/src/bench) compiled against the user's own client jar: it creates the world with WorldOpenFlows.createFreshLevel, teleports with /tp and places the player on the path every frame as horizon-ctl fly does. Nothing of the game is redistributed and the performance mods are fetched from Modrinth with the hashes pinned in packs/mods.lock.json. Horizon side: `fly ... PITCH raw` also replies with every frame time, and --offscreen drives frames from the event loop, so a window nobody sees (a locked macOS session) still renders. docs/benchmark.md describes what is measured, how fairness is kept, the caveats and how to reproduce it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
36 lines
1.4 KiB
Python
36 lines
1.4 KiB
Python
import unittest
|
|
|
|
from tools.perf_bench import OPTIONS, stats
|
|
|
|
|
|
class PerfBenchStatsTests(unittest.TestCase):
|
|
def test_lows_average_the_slowest_frames(self):
|
|
times = [10.0] * 990 + [100.0] * 9 + [1000.0]
|
|
s = stats(times)
|
|
self.assertEqual(s["frames"], 1000)
|
|
self.assertAlmostEqual(s["avg_fps"], 1000 * 1000 / (9900 + 900 + 1000))
|
|
# Slowest 1%: 9 frames of 100 ms and one of 1000 ms.
|
|
self.assertAlmostEqual(s["low_1pct_fps"], 1000 * 10 / 1900)
|
|
# Slowest 0.1%: the single 1000 ms frame.
|
|
self.assertAlmostEqual(s["low_01pct_fps"], 1.0)
|
|
self.assertEqual(s["p50_ms"], 10.0)
|
|
self.assertEqual(s["p99_ms"], 10.0)
|
|
self.assertEqual(s["p999_ms"], 100.0)
|
|
self.assertEqual(s["max_ms"], 1000.0)
|
|
self.assertAlmostEqual(sum(s["histogram"].values()), 1.0)
|
|
self.assertAlmostEqual(s["histogram"][">=100ms"], 0.01)
|
|
|
|
def test_a_short_flight_still_has_lows(self):
|
|
s = stats([5.0, 20.0])
|
|
self.assertAlmostEqual(s["low_1pct_fps"], 50.0)
|
|
self.assertAlmostEqual(s["low_01pct_fps"], 50.0)
|
|
self.assertEqual(stats([]), {"frames": 0})
|
|
|
|
def test_one_options_file_sets_the_render_distance(self):
|
|
self.assertEqual(OPTIONS["renderDistance"].format(distance=16), "16")
|
|
self.assertEqual(OPTIONS["graphicsPreset"], '"custom"')
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|