add benchmark executable
This commit is contained in:
parent
d27c019cc4
commit
0b9f41cbf6
5 changed files with 74 additions and 3 deletions
10
CHANGELOG.md
10
CHANGELOG.md
|
@ -2,9 +2,13 @@
|
||||||
Game store page: https://crispypin.itch.io/marble-machinations
|
Game store page: https://crispypin.itch.io/marble-machinations
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
- added: changelog file
|
### added
|
||||||
- (dev) added: sub-tick visualisation in debug mode
|
- changelog file
|
||||||
- fixed: equal comparator did not output one of two incoming signals in some cases, depending on wire length and update order
|
- (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: 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
|
- 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
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,13 @@
|
||||||
name = "marble-machinations"
|
name = "marble-machinations"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
default-run = "marble-machinations"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
raylib = "5.0.2"
|
raylib = "5.0.2"
|
||||||
serde = { version = "1.0.210", features = ["derive"] }
|
serde = { version = "1.0.210", features = ["derive"] }
|
||||||
serde_json = "1.0.128"
|
serde_json = "1.0.128"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "bench"
|
||||||
|
path = "src/benchmark.rs"
|
||||||
|
|
13
benchmarks/aoc_2024_1a_level.json
Normal file
13
benchmarks/aoc_2024_1a_level.json
Normal file
File diff suppressed because one or more lines are too long
10
benchmarks/aoc_2024_1a_solution.json
Normal file
10
benchmarks/aoc_2024_1a_solution.json
Normal file
File diff suppressed because one or more lines are too long
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
Reference in a new issue