Add criterion benchmark
This commit is contained in:
parent
9cb7e25149
commit
6c2c34f9a3
6 changed files with 520 additions and 6 deletions
61
benches/bruteforce.rs
Normal file
61
benches/bruteforce.rs
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
|
||||
use factorio_blueprint::belt_finding::{brute_force::*, Direction, Position};
|
||||
|
||||
fn brute_force(c: &mut Criterion) {
|
||||
c.bench_function("simple", |b| {
|
||||
let mut p = BruteforceBuilder::new(6, 8);
|
||||
|
||||
p.add_path(
|
||||
(Position::new(1, 0), Direction::Down),
|
||||
(Position::new(0, 0), Direction::Up),
|
||||
);
|
||||
p.add_path(
|
||||
(Position::new(4, 0), Direction::Down),
|
||||
(Position::new(1, 7), Direction::Up),
|
||||
);
|
||||
|
||||
p.set_blocked_range(0, 2, 5, 5, true);
|
||||
|
||||
let p = p.build();
|
||||
|
||||
b.iter(|| {
|
||||
let mut g = p.clone();
|
||||
|
||||
while g.next_finish_state() {}
|
||||
|
||||
g.solution_count()
|
||||
});
|
||||
});
|
||||
c.bench_function("weaving", |b| {
|
||||
let mut p = BruteforceBuilder::new(14, 3);
|
||||
|
||||
p.add_path(
|
||||
(Position::new(0, 0), Direction::Right),
|
||||
(Position::new(13, 0), Direction::Right),
|
||||
);
|
||||
p.add_path(
|
||||
(Position::new(0, 1), Direction::Right),
|
||||
(Position::new(13, 1), Direction::Right),
|
||||
);
|
||||
p.add_path(
|
||||
(Position::new(0, 2), Direction::Right),
|
||||
(Position::new(13, 2), Direction::Right),
|
||||
);
|
||||
|
||||
p.set_blocked_range(3, 2, 10, 2, true);
|
||||
|
||||
let p = p.build();
|
||||
|
||||
b.iter(|| {
|
||||
let mut g = p.clone();
|
||||
|
||||
while g.next_finish_state() {}
|
||||
|
||||
g.solution_count()
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, brute_force);
|
||||
criterion_main!(benches);
|
||||
Loading…
Add table
Add a link
Reference in a new issue