Benchmark
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// the render benchmark's numbers, its report, and its level, which has to be the same in every run for runs to compare
|
||||
import { assert, assertEquals } from "@std/assert";
|
||||
import { type BenchmarkReport, format_report, frame_stats, parse_report } from "$/client/benchmark/report.ts";
|
||||
import { bench_blocks, BenchTerrain, ZONES } from "$/client/benchmark/bench_level.ts";
|
||||
import { type BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import { AIR, CHUNK_SIZE, ID_MASK } from "$/common/constants.ts";
|
||||
import { test_game } from "./helpers.ts";
|
||||
|
||||
Deno.test("the lows are the fps of the slowest frames", () => {
|
||||
// 2% of the frames take five times as long
|
||||
const stats = frame_stats([...new Array(980).fill(10), ...new Array(20).fill(50)])!;
|
||||
assertEquals(stats.frames, 1000);
|
||||
assertEquals(stats.median_fps, 100);
|
||||
assertEquals(stats.low_1_fps, 20);
|
||||
assertEquals(stats.low_01_fps, 20);
|
||||
assertEquals(stats.max_ms, 50);
|
||||
assert(stats.fps < 100 && stats.fps > 20, "the average is in between");
|
||||
assertEquals(frame_stats([]), undefined);
|
||||
});
|
||||
|
||||
Deno.test("a report reads back from what was copied", () => {
|
||||
const scene = { draw_calls: 10, quads: 1000, chunks_in_view: 4, entities_in_view: 0 };
|
||||
const report: BenchmarkReport = {
|
||||
version: 1,
|
||||
date: "2026-01-01T00:00:00.000Z",
|
||||
system: {
|
||||
browser: "Firefox 150.0",
|
||||
os: "Linux x86_64",
|
||||
user_agent: "",
|
||||
cpu_threads: 8,
|
||||
gpu: "unknown gpu",
|
||||
gpu_features: [],
|
||||
timestamps: false,
|
||||
canvas_format: "bgra8unorm",
|
||||
device_pixel_ratio: 1,
|
||||
screen: "1920x1080",
|
||||
workers: 4,
|
||||
},
|
||||
mods: ["bworld 1.0.0"],
|
||||
resolution: "1920x1080",
|
||||
level: { chunks: 4, build_ms: 12.5 },
|
||||
first_mesh: { chunks: 1, ms: 100 },
|
||||
remesh: { chunks: 1, ms: 50 },
|
||||
scenes: { sky: { ...scene, paced: frame_stats([16, 16, 18]) }, terrain: scene },
|
||||
};
|
||||
const text = format_report(report);
|
||||
assert(text.includes("| terrain |"), "a table to read");
|
||||
const read = parse_report(text);
|
||||
assertEquals(read.scenes.terrain, scene);
|
||||
assertEquals(read.system, report.system);
|
||||
assertEquals(read.scenes.sky.paced!.fps.toFixed(2), report.scenes.sky.paced!.fps.toFixed(2));
|
||||
});
|
||||
|
||||
Deno.test("the benchmark's level comes out the same every time, with terrain in every layer", async () => {
|
||||
await test_game("mods");
|
||||
const blocks = bench_blocks(new Set());
|
||||
const chunk = (x: number, z: number) => new BenchTerrain(blocks).chunk(x, z).blocks;
|
||||
const lake = [Math.floor(ZONES.lake.x / CHUNK_SIZE), Math.floor(ZONES.lake.z / CHUNK_SIZE)] as const;
|
||||
const near_lake = [lake[0] + 3, lake[1] + 3] as const;
|
||||
assertEquals(chunk(0, 0), chunk(0, 0));
|
||||
assertEquals(chunk(...lake), chunk(...lake));
|
||||
|
||||
const registry = EverythingRegistry.get_registry<BlockRegistry>("blocks");
|
||||
const layers = new Set<string>();
|
||||
for (const [x, z] of [[0, 0], lake, near_lake, [5, 5]] as const) {
|
||||
for (const value of chunk(x, z)) {
|
||||
const nid = value & ID_MASK;
|
||||
if (nid !== AIR) layers.add(registry[nid].render_layer ?? "solid");
|
||||
}
|
||||
}
|
||||
assertEquals([...layers].sort(), ["cutout", "solid", "translucent"]);
|
||||
});
|
||||
Reference in New Issue
Block a user