shark/fish/benches/think.rs

81 lines
2.0 KiB
Rust
Raw Normal View History

2023-04-15 22:46:59 +00:00
use criterion::{BenchmarkId, Criterion};
use fish::eval::Weights;
use mino::srs::PieceType::*;
use mino::srs::{Piece, Queue};
use mino::{mat, Mat};
static MATRIX_0: &Mat = mat! {
"xxxxxxxx.x";
"xxxxxxx.xx";
"xxxx.xxxxx";
".xxxxxxxxx";
"xxxxx.xxxx";
"xxxx.xxxxx";
"xxxxxx.xxx";
".xxxxxxxxx";
"xxxxx.xxxx";
};
static MATRIX_1: &Mat = mat! {
"...S..JJJ.";
"...SSTLLJZ";
".xxxxxxxxx";
"xxxxx.xxxx";
"xxxx.xxxxx";
"xxxxxx.xxx";
".xxxxxxxxx";
"xxxxx.xxxx";
};
static MATRIX_2: &Mat = mat! {
".S.T......";
".SSTT.....";
"xxxxxxx.xx";
"xxxx.xxxxx";
"xx.xxxxxxx";
"x.xxxxxxxx";
"xxxxxxxxx.";
"xxx.xxxxxx";
"xxxxx.xxxx";
};
static MATRIX_3: &Mat = mat! {
"..OOSLL...";
".ZOOSSLI..";
"ZZZJJSLI..";
"xxxxxxxxx.";
"xxxxxxxx.x";
"xxxxxxxxx.";
"xxxxxx.xxx";
"xxxxxxx.xx";
"xxxxxx.xxx";
};
static QUEUE_0: Queue<'_> = Queue::new(None, &[I, S, T, Z, L]);
static QUEUE_1: Queue<'_> = Queue::new(Some(J), &[O, L, O, I, S]);
static QUEUE_2: Queue<'_> = Queue::new(Some(S), &[Z, L, J, I, O]);
static QUEUE_3: Queue<'_> = Queue::new(Some(L), &[S, J, T, Z, I]);
static MATRIX: &[&Mat] = &[MATRIX_0, MATRIX_1, MATRIX_2, MATRIX_3];
static QUEUE: &[Queue<'_>] = &[QUEUE_0, QUEUE_1, QUEUE_2, QUEUE_3];
const ITERS: u32 = 50_000;
fn think(iters: u32, weights: &Weights, matrix: &Mat, queue: Queue<'_>) -> Option<Piece> {
let mut bot = fish::bot::Bot::new(weights, matrix, queue);
2024-02-23 19:29:23 +00:00
bot.think(iters);
2023-04-15 22:46:59 +00:00
bot.suggest()
}
fn benchmark(c: &mut Criterion) {
let mut c = c.benchmark_group("think");
c.measurement_time(std::time::Duration::from_secs(10));
for i in 0..4 {
c.bench_with_input(
BenchmarkId::from_parameter(i),
&(ITERS, Weights::default(), MATRIX[i], QUEUE[i]),
2023-04-16 21:56:33 +00:00
|b, (i, w, m, q)| b.iter(|| think(*i, w, m, *q)),
2023-04-15 22:46:59 +00:00
);
}
c.finish();
}
criterion::criterion_group!(benches, benchmark);
criterion::criterion_main!(benches);