pce_bench/
pce-bench.rs

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