Benchmark

This commit is contained in:
2026-10-28 11:42:58 -03:00
parent e5221ba681
commit 8fc08ab41e
15 changed files with 1356 additions and 41 deletions
+18 -2
View File
@@ -12,6 +12,14 @@ export interface SectionStats {
max: number;
}
// one frame, in ms
export interface FrameSample {
// since the frame before started
interval: number;
// the javascript part
frame: number;
}
// what the client spends its time on, for the f3 performance window. each section is timed on the cpu, and on the gpu
// too when the renderer can, see gpu_section
class Profiler {
@@ -20,11 +28,14 @@ class Profiler {
frame: SectionStats = { avg: 0, max: 0 };
// the time between frames, which is what the player feels, and the javascript part of it
interval: SectionStats & { fps: number } = { avg: 0, max: 0, fps: 0 };
// every frame, while something reads them, like the benchmark
samples: FrameSample[] | undefined;
#window_start = performance.now();
#frames = 0;
#frame_start = 0;
#last_frame_start = 0;
#interval = 0;
#sums = new Map<string, number>();
#maxes = new Map<string, number>();
// this frame's time per section, added to the sums when it ends
@@ -32,14 +43,19 @@ class Profiler {
begin_frame() {
const now = performance.now();
if (this.#last_frame_start > 0) this.#add("interval", now - this.#last_frame_start);
if (this.#last_frame_start > 0) {
this.#interval = now - this.#last_frame_start;
this.#add("interval", this.#interval);
}
this.#last_frame_start = this.#frame_start = now;
this.#this_frame.clear();
}
end_frame() {
const now = performance.now();
this.#add("frame", now - this.#frame_start);
const frame = now - this.#frame_start;
this.#add("frame", frame);
this.samples?.push({ interval: this.#interval, frame });
for (const [name, ms] of this.#this_frame) this.#add(`cpu:${name}`, ms);
this.#frames += 1;
if (now - this.#window_start >= WINDOW_MS) this.#publish(now);