add benchmark for think()

This commit is contained in:
tali 2023-04-15 18:46:59 -04:00
parent bd840d5705
commit e15637f0dd
2 changed files with 84 additions and 0 deletions

View File

@ -23,3 +23,7 @@ harness = false
[[bench]] [[bench]]
name = "evaluation" name = "evaluation"
harness = false harness = false
[[bench]]
name = "think"
harness = false

80
fish/benches/think.rs Normal file
View File

@ -0,0 +1,80 @@
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);
bot.think_for(iters);
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]),
|b, (i, w, m, q)| b.iter(|| think(*i, w, *m, *q)),
);
}
c.finish();
}
criterion::criterion_group!(benches, benchmark);
criterion::criterion_main!(benches);