#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """The reference's speed on arm7-bench's workload, for the ratio in docs/status.md: the 15 CPU test ROMs from a fresh harness each, the suite repeated, best of 7 trials of about 2 s of CPU time (PyPy's JIT warms up in the first). Run with the reference's interpreter (scripts/env.sh). reference_bench.py """ from __future__ import annotations import os import sys import time from pathlib import Path from arm7tdmi_python.harness import Harness sys.path.insert(0, str(Path(__file__).resolve().parent)) from make_scenarios import ROMS # noqa: E402 def suite(roms: list[bytes]) -> int: steps = 0 for rom in roms: harness = Harness(rom) cpu = harness.cpu while not harness.at_branch_to_self(): cpu.step() steps += 1 return steps def main() -> int: base = Path(os.environ["TEST_ROMS"]) roms = [(base / r).read_bytes() for r in ROMS] steps = suite(roms) best = float("inf") for _ in range(7): start, passes = time.process_time(), 0 while time.process_time() - start < 2.0 or not passes: suite(roms) passes += 1 best = min(best, (time.process_time() - start) / passes) print(f"{len(roms)} ROMs, {steps} instructions a pass: {best * 1e3:.1f} ms a pass, " f"{steps / best / 1e6:.3f} M instructions/s (CPU time, {sys.implementation.name} {sys.version.split()[0]})") return 0 if __name__ == "__main__": sys.exit(main())