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

feat: initial benchark support for neo

parent 5f80ce06
No related branches found
No related tags found
No related merge requests found
Pipeline #567 passed
use chip_ahoyto::{chip8::Chip8, util::read_file};
use chip_ahoyto::{chip8::Chip8, chip8_neo::Chip8Neo, util::read_file};
use time::Instant;
const CYCLE_COUNT: u64 = 1_000_000_000;
const CYCLE_COUNT: u64 = 5_000_000_000;
fn main() {
fn benchmark_chip8() {
let rom_path = "./resources/pong.ch8";
let rom = read_file(rom_path);
......@@ -15,7 +15,32 @@ fn main() {
let cycles = CYCLE_COUNT;
println!("Running {} cycles for {}", cycles, rom_path);
println!("[Chip8] Running {} cycles for {}", cycles, rom_path);
for _ in 0..CYCLE_COUNT {
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!(
"[Chip8] Took {} seconds or {:.2} MHz CPU",
duration_s, mega_second
);
}
fn benchmark_chip8_neo() {
let rom_path = "./resources/pong.ch8";
let mut chip8 = Chip8Neo::new();
let instant = Instant::now();
let cycles = CYCLE_COUNT;
println!("[Chip8Neo] Running {} cycles for {}", cycles, rom_path);
for _ in 0..CYCLE_COUNT {
chip8.tick();
......@@ -25,5 +50,13 @@ fn main() {
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);
println!(
"[Chip8Neo] Took {} seconds or {:.2} MHz CPU",
duration_s, mega_second
);
}
fn main() {
benchmark_chip8();
benchmark_chip8_neo();
}
......@@ -4,6 +4,10 @@ pub const RAM_SIZE: usize = 4096;
pub const STACK_SIZE: usize = 16;
pub const REGISTERS_SIZE: usize = 16;
/// The starting address for the ROM loading, should be
/// the initial PC position.
const ROM_START: usize = 0x200;
pub struct Chip8Neo {
ram: [u8; RAM_SIZE],
vram: [u8; DISPLAY_WIDTH * DISPLAY_HEIGHT],
......@@ -15,3 +19,26 @@ pub struct Chip8Neo {
dt: u8,
st: u8,
}
#[cfg_attr(feature = "web", wasm_bindgen)]
impl Chip8Neo {
#[cfg_attr(feature = "web", wasm_bindgen(constructor))]
pub fn new() -> Chip8Neo {
let chip8 = Chip8Neo {
ram: [0u8; RAM_SIZE],
vram: [0u8; DISPLAY_WIDTH * DISPLAY_HEIGHT],
stack: [0u16; STACK_SIZE],
registers: [0u8; REGISTERS_SIZE],
pc: ROM_START as u16,
i: 0x0,
sp: 0x0,
dt: 0x0,
st: 0x0,
};
chip8
}
pub fn tick(&mut self) {
self.pc += 0x2;
}
}
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