diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ac8b67cdfcb564e50f2bf6c1373a57abac69446c..7e001c454c158a38343f60174ed2024f9a2c232d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -127,3 +127,5 @@ jobs: run: cd frontends/sdl && cargo build --release - name: Run release version run: cd frontends/sdl && cargo run --release -- --headless --cycles 10000000 + - name: Run benchmark + run: cd frontends/sdl && cargo run --release -- --benchmark diff --git a/CHANGELOG.md b/CHANGELOG.md index e8354e3a2b855dc5d72e154fb001fa1e095fe829..e41b40b6af569fe5e8186c0ed1dc9f7f994c5035 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added * Support for the `clock_m()` function +* Benchmark CLI option in SDL ### Changed diff --git a/frontends/sdl/src/main.rs b/frontends/sdl/src/main.rs index b9ac2e86dc8420b6e7d2cb56d1fa145905dd17b8..58eb1b604a27a67d7436d5542cb196ee0b604db7 100644 --- a/frontends/sdl/src/main.rs +++ b/frontends/sdl/src/main.rs @@ -226,22 +226,22 @@ impl Emulator { let count = params.count; let chunk_size = params.chunk_size.unwrap_or(1); - let mut cycles = 0; + let mut cycles = 0u64; let initial = SystemTime::now(); if chunk_size > 1 { for _ in 0..(count / chunk_size) { - cycles += self.system.clock_m(chunk_size) as u32; + cycles += self.system.clock_m(chunk_size) as u64; } } else { for _ in 0..count { - cycles += self.system.clock() as u32; + cycles += self.system.clock() as u64; } } - let delta = initial.elapsed().unwrap().as_millis() as f32 / 1000.0; - let frequency_mhz = cycles as f32 / delta / 1000.0 / 1000.0; + let delta = initial.elapsed().unwrap().as_millis() as f64 / 1000.0; + let frequency_mhz = cycles as f64 / delta / 1000.0 / 1000.0; println!( "Took {:.2} seconds to run {} ticks ({} cycles) ({:.2} Mhz)!", @@ -607,6 +607,13 @@ struct Args { #[arg(long, default_value_t = false, help = "If set no timer will be used")] no_timer: bool, + #[arg( + long, + default_value_t = false, + help = "Run in benchmark mode, with no UI" + )] + benchmark: bool, + #[arg( long, default_value_t = false, @@ -663,7 +670,7 @@ fn main() { let options = EmulatorOptions { auto_mode: Some(auto_mode), unlimited: Some(args.unlimited), - features: if args.headless { + features: if args.headless || args.benchmark { Some(vec![]) } else { Some(vec!["video", "audio", "no-vsync"]) @@ -677,7 +684,9 @@ fn main() { // determines if the emulator should run in headless mode or // not and runs it accordingly, note that if running in headless // mode the number of cycles to be run may be specified - if args.headless { + if args.benchmark { + emulator.benchmark(Benchmark::new(500000000, None)); + } else if args.headless { emulator.run_headless(if args.cycles > 0 { Some(args.cycles) } else {