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

feat: better benchmark support

parent f3c17675
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,9 @@ license = "Apache-2.0" ...@@ -7,6 +7,9 @@ license = "Apache-2.0"
keywords = ["chip-8", "emulator", "rust", "benchmark"] keywords = ["chip-8", "emulator", "rust", "benchmark"]
edition = "2018" edition = "2018"
[dependencies]
time = { version = "0.3" }
[dependencies.chip-ahoyto] [dependencies.chip-ahoyto]
path = "../.." path = "../.."
......
use chip_ahoyto::chip8::Chip8; use chip_ahoyto::chip8::Chip8;
use std::{fs::File, io::Read}; use std::{fs::File, io::Read};
use time::Instant;
const CYCLE_COUNT: u32 = 1_000_000_000; const CYCLE_COUNT: u64 = 10_000_000_000;
fn main() { fn main() {
let rom = read_file("./resources/pong.ch8"); let rom = read_file("./resources/pong.ch8");
...@@ -10,11 +11,21 @@ fn main() { ...@@ -10,11 +11,21 @@ fn main() {
chip8.reset_hard(); chip8.reset_hard();
chip8.load_rom(&rom); chip8.load_rom(&rom);
println!("Running {} cycles", CYCLE_COUNT); let instant = Instant::now();
let cycles = CYCLE_COUNT;
println!("Running {} cycles", cycles);
for _ in 0..CYCLE_COUNT { for _ in 0..CYCLE_COUNT {
chip8.tick(); chip8.tick();
} }
let duration_s = instant.elapsed().as_seconds_f32();
let cycles_second = cycles as f32 / duration_s;
let mega_second = cycles_second / 1000.0 / 1000.0;
println!("Took {} seconds or {:.2} MHz CPU", duration_s, mega_second);
} }
fn read_file(path: &str) -> Vec<u8> { fn read_file(path: &str) -> Vec<u8> {
......
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