Add blueprints directory and generalize benchmark and tests.
This commit is contained in:
parent
96a86779f4
commit
02e65f6fe3
12 changed files with 75 additions and 38 deletions
|
|
@ -1,30 +1,32 @@
|
|||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
|
||||
use factorio_blueprint::belt_finding::brute_force::problems::{simple, snake};
|
||||
use factorio_blueprint::belt_finding::brute_force::problems::{mid, simple, snake};
|
||||
|
||||
macro_rules! bench_bruteforce {
|
||||
($b:ident; $i:ident) => {
|
||||
|
||||
$b.bench_function(stringify!($i), |b| {
|
||||
let p = $i();
|
||||
|
||||
b.iter(|| {
|
||||
let mut b = p.clone();
|
||||
|
||||
while b.next_finish_state() {}
|
||||
|
||||
b.solution_count()
|
||||
});
|
||||
})
|
||||
};
|
||||
($b:ident; $i:ident $($is:ident )+) => {
|
||||
|
||||
bench_bruteforce!($b; $i);
|
||||
bench_bruteforce!($b; $($is)+);
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
fn brute_force(c: &mut Criterion) {
|
||||
c.bench_function("simple", |b| {
|
||||
let p = simple();
|
||||
|
||||
b.iter(|| {
|
||||
let mut g = p.clone();
|
||||
|
||||
while g.next_finish_state() {}
|
||||
|
||||
g.solution_count()
|
||||
});
|
||||
});
|
||||
c.bench_function("weaving", |b| {
|
||||
let p = snake();
|
||||
|
||||
b.iter(|| {
|
||||
let mut g = p.clone();
|
||||
|
||||
while g.next_finish_state() {}
|
||||
|
||||
g.solution_count()
|
||||
});
|
||||
});
|
||||
bench_bruteforce!(c; simple mid snake);
|
||||
}
|
||||
|
||||
criterion_group!(benches, brute_force);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue