#!/usr/bin/env python3 """Compare the v20 transition-column cache with the uncached v20 binary.""" import re import subprocess import time from pathlib import Path ROOT = Path(__file__).resolve().parents[4] OUT = ROOT / "Saved/Linux/l32" BINARIES = { "base": OUT / "bin/VoxelForgeCoreHeadless-l32-clang-v20", "cache": OUT / "bin/transition-cache/VoxelForgeCoreHeadless-l32-transition-cache", } ORDER = (("base", "cache"), ("cache", "base"), ("base", "cache"), ("cache", "base"), ("base", "cache")) READY = re.compile(r"\bwhole_view_ready=([0-9.]+)s") rows = [] failed = False for pair, builds in enumerate(ORDER, 1): for build in builds: name = f"cache-compare-sw-pair{pair}-{build}" logfile = OUT / f"{name}.log" command = [ "taskset", "-c", "0-11", "prlimit", "--as=6442450944", "--", str(BINARIES[build]), str(ROOT / "Standalone/data/owner_world.json"), "--workers=12", "--world-assembler-prototype", "--stream-benchmark", "--stream-pipeline", "--force-generate", "--clip-radius=3", "--max-clip-level=8", "--max-level=-1", "--recipe=surface-world", ] started = time.monotonic() try: with logfile.open("w", encoding="utf-8") as stream: result = subprocess.run(command, stdout=stream, stderr=subprocess.STDOUT, timeout=900, check=False) except subprocess.TimeoutExpired: result = None elapsed = time.monotonic() - started text = logfile.read_text(encoding="utf-8", errors="replace") matches = READY.findall(text) valid = result is not None and result.returncode == 0 and len(matches) == 1 ready = float(matches[0]) if len(matches) == 1 else float("nan") rows.append((pair, build, ready, elapsed, result.returncode if result else "TIMEOUT", valid)) print(f"pair={pair} build={build} whole_view_ready={ready:.3f}s " f"process_elapsed={elapsed:.1f}s {'PASS' if valid else 'FAIL'}", flush=True) failed |= not valid csv = OUT / "transition-cache-compare.csv" csv.write_text( "pair,build,whole_view_ready_seconds,process_elapsed_seconds,exit_code,status\n" + "".join(f"{pair},{build},{ready:.6f},{elapsed:.3f},{code}," f"{'PASS' if ok else 'FAIL'}\n" for pair, build, ready, elapsed, code, ok in rows), encoding="utf-8") for build in BINARIES: values = [row[2] for row in rows if row[1] == build] values.sort() median = values[len(values) // 2] print(f"[TransitionCacheCost] build={build} median_whole_view_ready_s={median:.3f}") print(f"[TransitionCacheCost] runs={len(rows)} status={'FAIL' if failed else 'PASS'}") raise SystemExit(1 if failed or len(rows) != 10 else 0)