-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Benchmark neural net inputs generation
- Loading branch information
1 parent
5edf1d0
commit db06af9
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use crate::helper::{contact_positions, race_positions}; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use engine::inputs::{ContactInputsGen, InputsGen, RaceInputsGen}; | ||
use engine::position::Position; | ||
use std::hint::black_box; | ||
|
||
mod helper; | ||
|
||
// This file contains benchmarks for generating neural net inputs for a given position. | ||
|
||
// Helper Methods | ||
|
||
fn sum_of_all_inputs<T: InputsGen>(positions: &[Position], inputs_gen: &T) { | ||
// Create 20 inputs at once. Should have roughly the same size as number of legal moves from a random position. | ||
let batch_size = 20; | ||
positions.chunks_exact(batch_size).for_each(|chunk| { | ||
inputs_gen.inputs_for_all(chunk); | ||
}); | ||
} | ||
|
||
// Benchmark methods | ||
|
||
#[allow(dead_code)] | ||
fn contact_inputs(c: &mut Criterion) { | ||
let positions = contact_positions(); | ||
let inputs_gen = ContactInputsGen {}; | ||
|
||
c.bench_function("generate inputs for: contact", |b| { | ||
b.iter(|| sum_of_all_inputs(black_box(&positions), &inputs_gen)) | ||
}); | ||
} | ||
|
||
#[allow(dead_code)] | ||
fn race_inputs(c: &mut Criterion) { | ||
let positions = race_positions(); | ||
let inputs_gen = RaceInputsGen {}; | ||
|
||
c.bench_function("generate inputs for: race", |b| { | ||
b.iter(|| sum_of_all_inputs(black_box(&positions), &inputs_gen)) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, contact_inputs, race_inputs); | ||
criterion_main!(benches); |