core: Add performance benchmark
Former-commit-id: 0fcda8fb5b8a506e22f74d0ef186a38708ed4def Former-commit-id: fd390604a7e01d9a67ffa0a70c5e9863f65fc9f8
This commit is contained in:
parent
ebd58261ba
commit
22f544718a
6
core/BENCHMARK.md
Normal file
6
core/BENCHMARK.md
Normal file
|
@ -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
|
||||||
|
|
|
@ -51,6 +51,10 @@ bit = "^0.1"
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
criterion = "0.3"
|
criterion = "0.3"
|
||||||
|
|
||||||
|
[[bench]]
|
||||||
|
name = "performance"
|
||||||
|
harness = false
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["arm7tdmi_dispatch_table"]
|
default = ["arm7tdmi_dispatch_table"]
|
||||||
elf_support = ["goblin"]
|
elf_support = ["goblin"]
|
||||||
|
|
63
core/benches/performance.rs
Normal file
63
core/benches/performance.rs
Normal file
|
@ -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);
|
4
core/benches/roms/README.md
Normal file
4
core/benches/roms/README.md
Normal file
|
@ -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
|
BIN
core/benches/roms/bigmap.gba
Executable file
BIN
core/benches/roms/bigmap.gba
Executable file
Binary file not shown.
BIN
core/benches/roms/normatt_gba_bios.bin
Normal file
BIN
core/benches/roms/normatt_gba_bios.bin
Normal file
Binary file not shown.
Reference in a new issue