Skip to content

Commit

Permalink
[rs] try benchmark with divan
Browse files Browse the repository at this point in the history
  • Loading branch information
shish committed Apr 8, 2024
1 parent 042789b commit c0f2d7b
Show file tree
Hide file tree
Showing 4 changed files with 209 additions and 16 deletions.
173 changes: 158 additions & 15 deletions rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ anyhow = "1"
clap = { version = "4.5.4", features = ["derive"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
divan = "0.1.0"

[profile.release-lto]
inherits = "release"
lto = true
lto = true

[dev-dependencies]
divan = "0.1.0"

[[bench]]
name = "scratch"
harness = false
31 changes: 31 additions & 0 deletions rs/benches/scratch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use clap::Parser;

fn main() {
divan::main();
}

#[divan::bench]
fn tick(bencher: divan::Bencher) {
let args = rosettaboy_rs::args::Args::parse_from([
"rosettaboy_rs", "--silent", "--headless", "--turbo",
"../gb-autotest-roms/blargg-cpu-instructions/01-special.gb"
].iter());
let mut gb = rosettaboy_rs::gameboy::GameBoy::new(args).unwrap();
bencher.bench_local(|| gb.tick().unwrap());
}

#[divan::bench]
fn ram_get() -> u64 {
let ram = rosettaboy_rs::ram::RAM::new(
rosettaboy_rs::cart::Cart::new(
"../gb-autotest-roms/blargg-cpu-instructions/01-special.gb"
).unwrap(),
false,
)
.unwrap();
let mut sum = 0;
for i in 0..0x3FFF {
sum += ram.get(i as u16);
}
sum as u64
}
11 changes: 11 additions & 0 deletions rs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pub mod args;
pub mod apu;
pub mod buttons;
pub mod cart;
pub mod clock;
pub mod cpu;
pub mod consts;
pub mod errors;
pub mod gameboy;
pub mod gpu;
pub mod ram;

0 comments on commit c0f2d7b

Please sign in to comment.