kobodl/bench.cpp
Ville Lindholm 0263be65d4
Add deterministic bench harness (KOBO_BENCH=1)
When KOBO_BENCH=1 is set in the environment, the game becomes a
hands-off benchmark:

  * Skips the intro/menu sequence and pushes st_game directly with
    scene=0, skill=CLASSIC, invulnerable ship, always_fire = constant
    auto-fire, countdown = 0 so "GET READY" auto-pops in 700ms.
  * Seeds pubrand and gamerand from KOBO_BENCH_SEED (default 12345)
    so the map, stress spawn pattern, and enemy AI are identical
    run-to-run.
  * Defaults KOBO_STRESS=1500 unless overridden, so the move pass has
    a steady workload, and KOBO_PROF=1 so the profiler is on.
  * Counts frames in run_game; after KOBO_BENCH_FRAMES (default 1800)
    it dumps prof to stderr and exits cleanly.

Usage from repo root (the cwd matters — relative GFX paths only
resolve from here):
    KOBO_BENCH=1 ./build/kobodl 2>bench-logs/phaseN.log

A single command produces a comparable profiler dump at every phase
of the DOD refactor — no menus to navigate, no keyboard input,
identical workload.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-04 15:37:44 +03:00

36 lines
1.0 KiB
C++

#include "bench.h"
#include <stdio.h>
#include <stdlib.h>
int kobo_bench_enabled = 0;
int kobo_bench_frames = 1800;
Uint32 kobo_bench_seed = 12345;
extern "C" void kobo_bench_init_env(void)
{
const char *e = getenv("KOBO_BENCH");
kobo_bench_enabled = (e && *e && *e != '0') ? 1 : 0;
const char *f = getenv("KOBO_BENCH_FRAMES");
if (f && *f) kobo_bench_frames = atoi(f);
const char *s = getenv("KOBO_BENCH_SEED");
if (s && *s) kobo_bench_seed = (Uint32)strtoul(s, NULL, 10);
if (!kobo_bench_enabled) return;
// Default a steady stress workload so the move pass has predictable cost.
if (!getenv("KOBO_STRESS"))
setenv("KOBO_STRESS", "1500", 1);
// Profiler is the whole point of running in bench mode.
if (!getenv("KOBO_PROF"))
setenv("KOBO_PROF", "1", 1);
fprintf(stderr,
"[bench] enabled: frames=%d seed=%u stress=%s prof=%s\n",
kobo_bench_frames,
(unsigned)kobo_bench_seed,
getenv("KOBO_STRESS"),
getenv("KOBO_PROF"));
}