#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """A/B two builds of a2600-bench on this shared machine: alternate them, game by game, on one pinned CPU, and compare their best runs (gameboy-rust-fast's scripts/ab.py, adapted). ab.py BIN_A BIN_B [--rounds N] [--frames N] [--cpu N] [--verbose] Each round runs A then B (then B then A the next round) on each game; the result is B's best speed over A's best, per game and overall (the geometric mean). The best, not the median: on a shared machine other work only ever slows a run down, so each side's fastest of many short runs is the closest to its own speed. The checksums (every finished line, every audio sample) must agree, or the builds do not compute the same thing and the comparison is refused. An A/A run shows the noise. Games come from $NO_INTRO_DIR: a 4K, an F8, the DPC, a PAL and a 2K cartridge. """ from __future__ import annotations import argparse import os import re import statistics import subprocess import sys NOINTRO = os.environ.get("NO_INTRO_DIR", "No-Intro") VCS = f"{NOINTRO}/Atari - Atari 2600" GAMES = [ f"ntsc:{VCS}/Pitfall! - Pitfall Harry's Jungle Adventure (USA).zip", f"ntsc:{VCS}/River Raid (USA).zip", f"ntsc:{VCS}/David Crane's Pitfall II - Lost Caverns (USA).zip", f"pal:{VCS}/Space Invaders (Europe).zip", f"ntsc:{VCS}/Combat (USA, Europe) (Atari Anthology).zip", ] LINE = re.compile(r"([\d.]+) frames/s, ([\d.]+)x real time, check ([0-9A-F]{8})") def bench(binary: str, game: str, frames: int, cpu: int) -> tuple[float, float, str]: out = subprocess.run( ["taskset", "-c", str(cpu), binary, game, "--frames", str(frames)], capture_output=True, text=True, check=True, ).stdout fps, realtime, check = LINE.search(out).groups() return float(fps), float(realtime), check def main() -> int: parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) parser.add_argument("a") parser.add_argument("b") parser.add_argument("--rounds", type=int, default=6) parser.add_argument("--frames", type=int, default=300) parser.add_argument("--cpu", type=int, default=31) args = parser.parse_args() ratios = [] for game in GAMES: a_runs, b_runs = [], [] for r in range(args.rounds): order = [("a", args.a), ("b", args.b)] if r % 2: order.reverse() for side, binary in order: result = bench(binary, game, args.frames, args.cpu) (a_runs if side == "a" else b_runs).append(result) checks = {c for *_, c in a_runs} | {c for *_, c in b_runs} name = game.split(":", 1)[0] + ":" + game.rsplit("/", 1)[-1].removesuffix(".zip") if len(checks) != 1: print(f"{name}: checksums differ {sorted(checks)}: the builds are not equivalent") return 1 a = max(s for s, *_ in a_runs) b = max(s for s, *_ in b_runs) a_rt = max(rt for _, rt, _ in a_runs) b_rt = max(rt for _, rt, _ in b_runs) ratios.append(b / a) print(f"{name}: A {a:.1f} frames/s ({a_rt:.2f}x RT), B {b:.1f} frames/s ({b_rt:.2f}x RT), x{b / a:.3f}", flush=True) # fmt: skip geo = statistics.geometric_mean(ratios) print(f"overall x{geo:.3f} (geometric mean of {len(ratios)} games, {args.rounds} rounds each)") return 0 if __name__ == "__main__": sys.exit(main())