pcecd_bench/
pcecd-bench.rs

1//! Frames per second of this machine on a disc, nothing logged or digested.
2//!
3//!     pcecd-bench CARD [--disc CUE] [--arcade] [--frames N] [options of trace::Setup]
4//!
5//! Speed is not this crate's goal (the fast fork's); `scripts/bench_cd.py` times the reference
6//! the same way.
7
8use std::time::Instant;
9
10use pcenginecd_rust::board::unit;
11use pcenginecd_rust::trace::Setup;
12
13fn main() {
14    let args: Vec<String> = std::env::args().skip(1).collect();
15    let setup = match Setup::parse(&args) {
16        Ok(setup) => setup,
17        Err(error) => {
18            eprintln!("pcecd-bench: {error}");
19            std::process::exit(1);
20        }
21    };
22    let mut system = setup.build().expect("a machine");
23    if let Some(unit) = unit(system.board_mut()) {
24        unit.bus.record_log = false;
25    }
26    let began = Instant::now();
27    let mut samples = 0;
28    for _ in 0..setup.frames {
29        setup.before_frame(&mut system);
30        system.run_frame();
31        samples += system.board_mut().take_audio().len();
32    }
33    let seconds = began.elapsed().as_secs_f64();
34    println!(
35        "{} frames in {:.3} s: {:.1} frames per second ({} audio samples, mclk {})",
36        setup.frames,
37        seconds,
38        setup.frames as f64 / seconds,
39        samples,
40        system.board().mclk
41    );
42}