add benchmark executable
This commit is contained in:
parent
d27c019cc4
commit
0b9f41cbf6
5 changed files with 74 additions and 3 deletions
39
src/benchmark.rs
Normal file
39
src/benchmark.rs
Normal file
|
@ -0,0 +1,39 @@
|
|||
use std::time::Instant;
|
||||
|
||||
use marble_machinations::{
|
||||
level::Level,
|
||||
marble_engine::{board::Board, Machine},
|
||||
solution::Solution,
|
||||
};
|
||||
|
||||
fn main() {
|
||||
aoc_2024_1a();
|
||||
}
|
||||
|
||||
fn aoc_2024_1a() {
|
||||
println!("running aoc_2024_1a");
|
||||
benchmark(
|
||||
include_str!("../benchmarks/aoc_2024_1a_level.json"),
|
||||
include_str!("../benchmarks/aoc_2024_1a_solution.json"),
|
||||
);
|
||||
}
|
||||
|
||||
fn benchmark(level: &str, solution: &str) {
|
||||
let level: Level = serde_json::from_str(level).unwrap();
|
||||
let solution: Solution = serde_json::from_str(solution).unwrap();
|
||||
let cycle_count = solution.score.unwrap().cycles;
|
||||
let mut machine = Machine::new_empty();
|
||||
machine.set_board(Board::parse(&solution.board));
|
||||
let start_time = Instant::now();
|
||||
for (n, stage) in level.stages().iter().enumerate() {
|
||||
machine.set_input(stage.input().as_bytes().to_owned());
|
||||
for _ in 0..cycle_count {
|
||||
machine.step();
|
||||
}
|
||||
assert_eq!(machine.output(), stage.output().as_bytes());
|
||||
println!("passed stage {n}");
|
||||
machine.reset();
|
||||
}
|
||||
let elapsed = start_time.elapsed();
|
||||
println!("took {elapsed:?}");
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue