diff --git a/core/BENCHMARK.md b/core/BENCHMARK.md new file mode 100644 index 0000000..edad29b --- /dev/null +++ b/core/BENCHMARK.md @@ -0,0 +1,6 @@ +# Performance benchmark + +rustboyadvance-core crate provides a simple yet effective performance benchmark. + +to run it use `cargo bench --manifest-path ./core/Cargo.toml --features no_video_interface` from the repository root + diff --git a/core/Cargo.toml b/core/Cargo.toml index f0f667f..ebaebba 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -51,6 +51,10 @@ bit = "^0.1" [dev-dependencies] criterion = "0.3" +[[bench]] +name = "performance" +harness = false + [features] default = ["arm7tdmi_dispatch_table"] elf_support = ["goblin"] diff --git a/core/benches/performance.rs b/core/benches/performance.rs new file mode 100644 index 0000000..23bb29b --- /dev/null +++ b/core/benches/performance.rs @@ -0,0 +1,63 @@ +/// Measure first 60 frames bigmap.gba from tonc demos +/// +use criterion::{black_box, criterion_group, criterion_main, BatchSize, Criterion}; + +use std::cell::RefCell; +use std::rc::Rc; + +use rustboyadvance_core::prelude::*; + +struct BenchmarkHardware {} +impl AudioInterface for BenchmarkHardware {} +impl InputInterface for BenchmarkHardware {} + +fn create_gba() -> GameBoyAdvance { + // TODO: do I really want this file in my repository ? + let bios = include_bytes!("roms/normatt_gba_bios.bin"); + let bigmap_rom = include_bytes!("roms/bigmap.gba"); + + let gpak = GamepakBuilder::new() + .take_buffer(bigmap_rom.to_vec().into_boxed_slice()) + .with_sram() + .without_backup_to_file() + .build() + .unwrap(); + + let dummy = Rc::new(RefCell::new(BenchmarkHardware {})); + + let mut gba = GameBoyAdvance::new( + bios.to_vec().into_boxed_slice(), + gpak, + dummy.clone(), + dummy.clone(), + ); + gba.skip_bios(); + // skip initialization of the ROM to get to a stabilized scene + for _ in 0..60 { + gba.frame(); + } + gba +} + +pub fn performance_benchmark(c: &mut Criterion) { + c.bench_function("run_60_frames", |b| { + b.iter_batched( + // setup + || create_gba(), + // bencher + |mut gba| { + for _ in 0..60 { + black_box(gba.frame()) + } + }, + BatchSize::SmallInput, + ) + }); +} + +criterion_group! { + name = benches; + config = Criterion::default().sample_size(10); + targets = performance_benchmark +} +criterion_main!(benches); diff --git a/core/benches/roms/README.md b/core/benches/roms/README.md new file mode 100644 index 0000000..e830618 --- /dev/null +++ b/core/benches/roms/README.md @@ -0,0 +1,4 @@ +# Files + +* bigmap.gba - This is a test rom from TONC, more test roms can be obtained from https://www.coranac.com/files/tonc-bin.zip +* normatt_gba_bios.bin - An open source GBA bios rom that can obtained from https://github.com/Nebuleon/ReGBA/raw/master/bios/gba_bios.bin diff --git a/core/benches/roms/bigmap.gba b/core/benches/roms/bigmap.gba new file mode 100755 index 0000000..a72111f Binary files /dev/null and b/core/benches/roms/bigmap.gba differ diff --git a/core/benches/roms/normatt_gba_bios.bin b/core/benches/roms/normatt_gba_bios.bin new file mode 100644 index 0000000..802982e Binary files /dev/null and b/core/benches/roms/normatt_gba_bios.bin differ