Skip to content
Snippets Groups Projects
Verified Commit 1fd28828 authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

chore: new benchmark modes

parent 04808c1a
No related branches found
No related tags found
1 merge request!24Performance optimisations
Pipeline #2833 passed
......@@ -129,3 +129,5 @@ jobs:
run: cd frontends/sdl && cargo run --release -- --headless --cycles 10000000
- name: Run benchmark
run: cd frontends/sdl && cargo run --release -- --benchmark
- name: Run benchmark, only for CPU
run: cd frontends/sdl && cargo run --release -- --benchmark --cpu-only
......@@ -40,17 +40,22 @@ const VOLUME: f32 = 64.0;
pub struct Benchmark {
count: usize,
chunk_size: Option<usize>,
cpu_only: Option<bool>,
}
impl Benchmark {
pub fn new(count: usize, chunk_size: Option<usize>) -> Self {
Self { count, chunk_size }
pub fn new(count: usize, cpu_only: Option<bool>, chunk_size: Option<usize>) -> Self {
Self {
count,
cpu_only,
chunk_size,
}
}
}
impl Default for Benchmark {
fn default() -> Self {
Self::new(50000000, None)
Self::new(50000000, None, None)
}
}
......@@ -221,13 +226,18 @@ impl Emulator {
self.load_rom(None);
}
pub fn benchmark(&mut self, params: Benchmark) {
pub fn benchmark(&mut self, params: &Benchmark) {
println!("Going to run benchmark...");
let count = params.count;
let chunk_size = params.chunk_size.unwrap_or(1);
let cpu_only = params.cpu_only.unwrap_or(false);
let mut cycles = 0u64;
if cpu_only {
self.system.set_all_enabled(false);
}
let initial = SystemTime::now();
if chunk_size > 1 {
......@@ -320,7 +330,7 @@ impl Emulator {
Event::KeyDown {
keycode: Some(Keycode::B),
..
} => self.benchmark(Benchmark::default()),
} => self.benchmark(&Benchmark::default()),
Event::KeyDown {
keycode: Some(Keycode::T),
..
......@@ -491,11 +501,16 @@ impl Emulator {
}
}
pub fn run_benchmark(&mut self, params: Benchmark) {
pub fn run_benchmark(&mut self, params: &Benchmark) {
let count = params.count;
let chunk_size = params.chunk_size.unwrap_or(1);
let cpu_only = params.cpu_only.unwrap_or(false);
let mut cycles = 0u64;
if cpu_only {
self.system.set_all_enabled(false);
}
let initial = SystemTime::now();
if chunk_size > 1 {
......@@ -640,6 +655,16 @@ struct Args {
)]
benchmark: bool,
#[arg(
long,
default_value_t = 500000000,
help = "The size of the benchmark in clock ticks"
)]
bench_count: usize,
#[arg(long, default_value_t = false, help = "Run benchmark only for the CPU")]
cpu_only: bool,
#[arg(
long,
default_value_t = false,
......@@ -711,7 +736,7 @@ fn main() {
// not and runs it accordingly, note that if running in headless
// mode the number of cycles to be run may be specified
if args.benchmark {
emulator.run_benchmark(Benchmark::new(500000000, None));
emulator.run_benchmark(&Benchmark::new(args.bench_count, Some(args.cpu_only), None));
} else if args.headless {
emulator.run_headless(if args.cycles > 0 {
Some(args.cycles)
......
......@@ -775,6 +775,14 @@ impl GameBoy {
(*self.gbc).borrow_mut().set_serial_enabled(value);
}
pub fn set_all_enabled(&mut self, value: bool) {
self.set_ppu_enabled(value);
self.set_apu_enabled(value);
self.set_dma_enabled(value);
self.set_timer_enabled(value);
self.set_serial_enabled(value);
}
pub fn clock_freq(&self) -> u32 {
self.clock_freq
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment