From 9a47c92d53c81d5b53ee715d98016fd5292491f0 Mon Sep 17 00:00:00 2001 From: BREW <81044362+b-re-w@users.noreply.github.com> Date: Sat, 3 Oct 2026 19:21:23 +0900 Subject: [PATCH] Bench: Record the measured commit in the result JSON Both measure and interleaved write the HEAD commit of the checkout the harness ran from (+dirty if tracked files differ), so a number can always be traced to the code it measured. Refs #41 --- benchmarks/typedpython/run.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/benchmarks/typedpython/run.py b/benchmarks/typedpython/run.py index 288cfd746..c9593805a 100644 --- a/benchmarks/typedpython/run.py +++ b/benchmarks/typedpython/run.py @@ -116,6 +116,14 @@ def commands(name: str, size: str, python: str, java_source: bool, return cmds +def source_commit() -> str: + """The commit the harness (and the TypedPython sources beside it) was measured at.""" + result = subprocess.run(["git", "-C", str(ROOT), "rev-parse", "HEAD"], capture_output=True, text=True) + dirty = subprocess.run(["git", "-C", str(ROOT), "status", "--porcelain", "--untracked-files=no"], + capture_output=True, text=True).stdout.strip() + return result.stdout.strip() + ("+dirty" if dirty else "") if result.returncode == 0 else "unknown" + + def run_once(cmd: list[str]) -> tuple[float, str]: start = time.perf_counter() result = subprocess.run(cmd, capture_output=True, text=True) @@ -190,6 +198,7 @@ def measure(args: argparse.Namespace) -> int: out_dir.mkdir(exist_ok=True) path = out_dir / f"{datetime.date.today().isoformat()}-{socket.gethostname()}.json" payload = {"date": datetime.datetime.now().isoformat(timespec="seconds"), + "commit": source_commit(), "host": socket.gethostname(), "load_average": load, "repeat": args.repeat, "python": subprocess.run([args.python, "--version"], capture_output=True, text=True).stdout.strip(), "results": results} @@ -248,6 +257,7 @@ def interleaved(args: argparse.Namespace) -> int: out_dir.mkdir(exist_ok=True) path = out_dir / f"{datetime.date.today().isoformat()}-{socket.gethostname()}-interleaved.json" path.write_text(json.dumps({"date": datetime.datetime.now().isoformat(timespec="seconds"), + "commit": source_commit(), "host": socket.gethostname(), "method": "interleaved A/B", "pairs": args.pairs, "results": results}, indent=2) + "\n") print(f"wrote {path}")