add benchmark executable

This commit is contained in:
Crispy 2025-03-27 19:21:10 +01:00
parent d27c019cc4
commit 0b9f41cbf6
5 changed files with 74 additions and 3 deletions

View file

@ -2,9 +2,13 @@
Game store page: https://crispypin.itch.io/marble-machinations
## [Unreleased]
- added: changelog file
- (dev) added: sub-tick visualisation in debug mode
- fixed: equal comparator did not output one of two incoming signals in some cases, depending on wire length and update order
### added
- changelog file
- (dev) sub-tick visualisation in debug mode
- (dev) tests and benchmarks
### fixed
- equal comparator did not output one of two incoming signals in some cases, depending on wire length and update order
### changed
- changed: comparators can now power other tiles without a wire between, including other comparators
- changed: directly moving marbles (to adjactent tile without anything between) now have priority over new marbles being created, instead of the two events cancelling each other

View file

@ -2,8 +2,13 @@
name = "marble-machinations"
version = "0.2.1"
edition = "2021"
default-run = "marble-machinations"
[dependencies]
raylib = "5.0.2"
serde = { version = "1.0.210", features = ["derive"] }
serde_json = "1.0.128"
[[bin]]
name = "bench"
path = "src/benchmark.rs"

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

39
src/benchmark.rs Normal file
View 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:?}");
}