// SPDX-License-Identifier: MIT //! Speed, for the record (not a goal of this tier): gilyon's cputest-full in //! the plain harness, from reset to its spin, best of `RUNS` runs. //! //! bench CPUTEST_DIR [RUNS] //! //! Prints instructions (steps that ran an instruction), bus cycles and the best //! run's time, and both rates. One thread; the harness's own work (its //! registers, instant DMA) is included, as a host's would be. use std::time::Instant; use w65c816::harness::Harness; use w65c816::trace::{next_boundary, BoundaryKind}; fn main() { let args: Vec = std::env::args().skip(1).collect(); let folder = std::path::Path::new(args.first().expect("usage: bench CPUTEST_DIR [RUNS]")); let runs: usize = args.get(1).map_or(5, |r| r.parse().expect("RUNS")); let rom = std::fs::read(folder.join("cputest-full.sfc")).expect("cputest-full.sfc"); let mut best = f64::INFINITY; let (mut instructions, mut cycles) = (0u64, 0u64); for _ in 0..runs { let mut harness = Harness::new(&rom); let started = Instant::now(); let mut count = 0u64; let result = harness.run_with(20_000_000, None, &mut |cpu| { if next_boundary(&cpu.capture_state()) == BoundaryKind::Instruction { count += 1; } cpu.step(); }); let seconds = started.elapsed().as_secs_f64(); assert_eq!(result.reason, "spin"); best = best.min(seconds); instructions = count; cycles = result.cycles; } // Without the per-step boundary check (a host's loop): the cycles alone. let mut plain = f64::INFINITY; for _ in 0..runs { let mut harness = Harness::new(&rom); let started = Instant::now(); harness.run(20_000_000, None); plain = plain.min(started.elapsed().as_secs_f64()); } println!( "cputest-full: {instructions} instructions, {cycles} cycles; best of {runs}: {plain:.4} s \ ({:.1} M instructions/s, {:.1} M cycles/s); counting boundaries {best:.4} s", instructions as f64 / plain / 1e6, cycles as f64 / plain / 1e6 ); }