From e15637f0dd6f07bf4aa8d9c73a3123490e44037c Mon Sep 17 00:00:00 2001 From: tali Date: Sat, 15 Apr 2023 18:46:59 -0400 Subject: [PATCH] add benchmark for think() --- fish/Cargo.toml | 4 +++ fish/benches/think.rs | 80 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 fish/benches/think.rs diff --git a/fish/Cargo.toml b/fish/Cargo.toml index 872eca7..4736e08 100644 --- a/fish/Cargo.toml +++ b/fish/Cargo.toml @@ -23,3 +23,7 @@ harness = false [[bench]] name = "evaluation" harness = false + +[[bench]] +name = "think" +harness = false diff --git a/fish/benches/think.rs b/fish/benches/think.rs new file mode 100644 index 0000000..917890a --- /dev/null +++ b/fish/benches/think.rs @@ -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 { + 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);