#!/usr/bin/env bash # The benchmark: four cartridges as the window runs them (md-bench), each from # power-on with sound and picture. Prints each workload's best time and a total. # # Usage: scripts/bench.sh [--frames N] [--repeat N] [--only NAME] # env: BENCH_BIN (default target/release/md-bench), ROMS (the local romset) set -euo pipefail ROOT=$(cd "$(dirname "$0")/.." && pwd) BIN=${BENCH_BIN:-"$ROOT/target/release/md-bench"} ROMS=${ROMS:-/data/emu/roms/megadrive} TEST_ROMS=${TEST_ROMS:-/data/emu/megadrive-python/tests/test_roms} FRAMES=1800 REPEAT=1 ONLY= while [ $# -gt 0 ]; do case $1 in --frames) FRAMES=$2; shift 2 ;; --repeat) REPEAT=$2; shift 2 ;; --only) ONLY=$2; shift 2 ;; *) echo "unknown argument $1" >&2; exit 2 ;; esac done # name, cartridge, arguments: the cold boots of the gate (scripts/cases.tsv), with play. workloads=( "sonic|$ROMS/Sonic The Hedgehog (USA, Europe).zip|--press start@700:710 --press right@900:1500 --press right,c@1500:1520 --press right@1520:2500" "sor2|$ROMS/Streets of Rage 2 (USA).zip|--press start@900:910 --press start@1100:1110 --press start@1300:1310 --press right@1500:2500" "gunstar|$ROMS/Gunstar Heroes (USA).zip|--press start@700:710 --press start@900:910 --press c@1100:1110 --press right@1300:2500" "od2|$TEST_ROMS/titan/titan-overdrive2.zip|" ) total=0 for w in "${workloads[@]}"; do IFS='|' read -r name cart args <<<"$w" [ -z "$ONLY" ] || [ "$ONLY" = "$name" ] || continue # shellcheck disable=SC2086 line=$("$BIN" "$cart" --frames "$FRAMES" --repeat "$REPEAT" $args) echo "$name: $line" total=$(awk "BEGIN{print $total + $(cut -d' ' -f1 <<<"$line")}") done echo "total $total s"