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 c3a6f80
Show file tree
Hide file tree
Showing 5 changed files with 221 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
7 changes: 7 additions & 0 deletions rs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ Usage
./rosettaboy-release game.gb
```

Benchmarks
----------
To benchmark a couple of internal bits:
```
cargo bench
```

Requirements
------------
- SDL2
Expand Down
36 changes: 36 additions & 0 deletions rs/benches/scratch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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 apu;
pub mod args;
pub mod buttons;
pub mod cart;
pub mod clock;
pub mod consts;
pub mod cpu;
pub mod errors;
pub mod gameboy;
pub mod gpu;
pub mod ram;

0 comments on commit c3a6f80

Please sign in to comment.