#!/usr/bin/env python3 """Run five interleaved W12 whole-view pairs against the L32 binary.""" import re import statistics import subprocess import time from pathlib import Path ROOT = Path(__file__).resolve().parents[4] OUT = ROOT / "Saved/Linux/l33" OUT.mkdir(parents=True, exist_ok=True) BINARIES = { "l32": ROOT / "Saved/Linux/l32/bin/VoxelForgeCoreHeadless-l32-clang-v20", "l33": OUT / "bin/VoxelForgeCoreHeadless-clang-l33-final", } ORDERS = (("l32", "l33"), ("l33", "l32"), ("l32", "l33"), ("l33", "l32"), ("l32", "l33")) READY = re.compile(r"\bwhole_view_ready=([0-9.]+)s") rows = [] failed = False for recipe in ("surface-world", "floating-islands"): for pair, order in enumerate(ORDERS, 1): for build in order: name = f"cost-{recipe}-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", f"--recipe={recipe}", ] 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) stamps = re.findall( r"^\[WorldAssemblerRecipeAudit\] requested=([^ ]+) actual=([^ ]+).*status=([^ ]+)$", text, re.M) stamp_ok = stamps == [(recipe, recipe, "PASS")] valid = (result is not None and result.returncode == 0 and len(matches) == 1 and "hash=off" in text and "cache_hits=0" in text and stamp_ok) ready = float(matches[0]) if len(matches) == 1 else float("nan") rows.append((recipe, pair, build, ready, elapsed, result.returncode if result else "TIMEOUT", valid)) print(f"{recipe} 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 summary = OUT / "cost-runs.csv" summary.write_text( "recipe,pair,build,whole_view_ready_seconds,process_elapsed_seconds,exit_code,status\n" + "".join(f"{recipe},{pair},{build},{ready:.6f},{elapsed:.3f},{code}," f"{'PASS' if ok else 'FAIL'}\n" for recipe, pair, build, ready, elapsed, code, ok in rows), encoding="utf-8") for recipe in ("surface-world", "floating-islands"): by_build = {build: [row[3] for row in rows if row[0] == recipe and row[2] == build] for build in BINARIES} baseline = statistics.median(by_build["l32"]) current = statistics.median(by_build["l33"]) paired = [] for pair in range(1, 6): values = {row[2]: row[3] for row in rows if row[0] == recipe and row[1] == pair} paired.append((values["l33"] - values["l32"]) / values["l32"] * 100.0) print(f"[L33CostSummary] recipe={recipe} pairs=5 median_l32_s={baseline:.3f} " f"median_l33_s={current:.3f} median_change_pct={(current/baseline-1)*100.0:+.2f} " f"paired_change_pct={','.join(f'{value:+.2f}' for value in paired)}", flush=True) print(f"[L33Cost] runs={len(rows)} status={'FAIL' if failed else 'PASS'} summary={summary}", flush=True) raise SystemExit(1 if failed or len(rows) != 20 else 0)