79 lines
1.9 KiB
Rust
79 lines
1.9 KiB
Rust
use criterion::{BenchmarkId, Criterion};
|
|
use mino::srs::PieceType::*;
|
|
use mino::srs::{Piece, Queue};
|
|
use mino::{mat, Mat};
|
|
|
|
pub static MATRIX_0: &Mat = mat! {
|
|
"xxxxxxxx.x";
|
|
"xxxxxxx.xx";
|
|
"xxxx.xxxxx";
|
|
".xxxxxxxxx";
|
|
"xxxxx.xxxx";
|
|
"xxxx.xxxxx";
|
|
"xxxxxx.xxx";
|
|
".xxxxxxxxx";
|
|
"xxxxx.xxxx";
|
|
};
|
|
pub static MATRIX_1: &Mat = mat! {
|
|
"...S..JJJ.";
|
|
"...SSTLLJZ";
|
|
".xxxxxxxxx";
|
|
"xxxxx.xxxx";
|
|
"xxxx.xxxxx";
|
|
"xxxxxx.xxx";
|
|
".xxxxxxxxx";
|
|
"xxxxx.xxxx";
|
|
};
|
|
pub static MATRIX_2: &Mat = mat! {
|
|
".S.T......";
|
|
".SSTT.....";
|
|
"xxxxxxx.xx";
|
|
"xxxx.xxxxx";
|
|
"xx.xxxxxxx";
|
|
"x.xxxxxxxx";
|
|
"xxxxxxxxx.";
|
|
"xxx.xxxxxx";
|
|
"xxxxx.xxxx";
|
|
};
|
|
pub static MATRIX_3: &Mat = mat! {
|
|
"..OOSLL...";
|
|
".ZOOSSLI..";
|
|
"ZZZJJSLI..";
|
|
"xxxxxxxxx.";
|
|
"xxxxxxxx.x";
|
|
"xxxxxxxxx.";
|
|
"xxxxxx.xxx";
|
|
"xxxxxxx.xx";
|
|
"xxxxxx.xxx";
|
|
};
|
|
pub static QUEUE_0: Queue<'_> = Queue::new(None, &[I, S, T, Z, L]);
|
|
pub static QUEUE_1: Queue<'_> = Queue::new(Some(J), &[O, L, O, I, S]);
|
|
pub static QUEUE_2: Queue<'_> = Queue::new(Some(S), &[Z, L, J, I, O]);
|
|
pub static QUEUE_3: Queue<'_> = Queue::new(Some(L), &[S, J, T, Z, I]);
|
|
|
|
pub static MATRIX: &[&Mat] = &[MATRIX_0, MATRIX_1, MATRIX_2, MATRIX_3];
|
|
pub static QUEUE: &[Queue<'_>] = &[QUEUE_0, QUEUE_1, QUEUE_2, QUEUE_3];
|
|
|
|
fn find_locations(mat: &Mat, queue: Queue<'_>) -> Vec<Piece> {
|
|
queue
|
|
.reachable()
|
|
.flat_map(|ty| fish::find::find_locations(mat, ty).map(move |loc| Piece { loc, ty }))
|
|
.collect()
|
|
}
|
|
|
|
fn benchmark(c: &mut Criterion) {
|
|
let mut c = c.benchmark_group("find_locations");
|
|
c.confidence_level(0.98);
|
|
for i in 0..4 {
|
|
c.bench_with_input(
|
|
BenchmarkId::from_parameter(i),
|
|
&(MATRIX[i], QUEUE[i]),
|
|
|b, (matrix, queue)| b.iter(|| find_locations(matrix, *queue)),
|
|
);
|
|
}
|
|
c.finish();
|
|
}
|
|
|
|
criterion::criterion_group!(benches, benchmark);
|
|
criterion::criterion_main!(benches);
|