Skip to content

Commit

Permalink
Add worst case AI benchmark
Browse files Browse the repository at this point in the history
The worst case AI update time is where a new game with an empty board
must be evaluated.

See issue #5.
  • Loading branch information
j-richey committed Dec 8, 2019
1 parent b7b4ac8 commit e1f70d7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ edition = "2018"

[dependencies]
rand = "0.7.2"

[dev-dependencies]
criterion = "0.3.0"

[[bench]]
name = "benchmarks"
harness = false
30 changes: 30 additions & 0 deletions benches/benchmarks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#[macro_use]
extern crate criterion;

use criterion::Criterion;

use open_ttt_lib::ai;
use open_ttt_lib::game;

fn flawless_ai_moves_benchmarks(c: &mut Criterion) {
let game = game::Game::new();
let mistake_probability = 0.0;
let ai_opponent = ai::Opponent::new(mistake_probability);

c.bench_function("New game with flawless AI", |b| {
b.iter(|| ai_opponent.get_move(&game))
});
}

fn build_benchmark_configuration() -> Criterion {
// At the moment the AI takes a LONG time to update so reduce
// the sample size so the test completes in this decade.
Criterion::default().sample_size(10)
}

criterion_group!(
name = benches;
config = build_benchmark_configuration();
targets = flawless_ai_moves_benchmarks);

criterion_main!(benches);

0 comments on commit e1f70d7

Please sign in to comment.