61 lines
1.5 KiB
Rust
61 lines
1.5 KiB
Rust
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);
|