Added benchmark for Batch
This commit is contained in:
62
benches/batch.rs
Normal file
62
benches/batch.rs
Normal file
@@ -0,0 +1,62 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
use trueskill_tt::{
|
||||
agent::Agent, batch::Batch, gaussian::Gaussian, player::Player, IndexMap, BETA, GAMMA, MU,
|
||||
P_DRAW, SIGMA,
|
||||
};
|
||||
|
||||
fn criterion_benchmark(criterion: &mut Criterion) {
|
||||
let mut index = IndexMap::new();
|
||||
|
||||
let a = index.get_or_create("a");
|
||||
let b = index.get_or_create("b");
|
||||
let c = index.get_or_create("c");
|
||||
|
||||
let agents = {
|
||||
let mut map = HashMap::new();
|
||||
|
||||
map.insert(
|
||||
a,
|
||||
Agent {
|
||||
player: Player::new(Gaussian::new(MU, SIGMA), BETA, GAMMA),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
map.insert(
|
||||
b,
|
||||
Agent {
|
||||
player: Player::new(Gaussian::new(MU, SIGMA), BETA, GAMMA),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
map.insert(
|
||||
c,
|
||||
Agent {
|
||||
player: Player::new(Gaussian::new(MU, SIGMA), BETA, GAMMA),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
|
||||
map
|
||||
};
|
||||
|
||||
let mut composition = Vec::new();
|
||||
let mut results = Vec::new();
|
||||
let mut weights = Vec::new();
|
||||
|
||||
for _ in 0..100 {
|
||||
composition.push(vec![vec![a], vec![b]]);
|
||||
results.push(vec![1.0, 0.0]);
|
||||
weights.push(vec![vec![1.0], vec![1.0]]);
|
||||
}
|
||||
|
||||
let mut batch = Batch::new(composition, results, weights, 1, P_DRAW, &agents);
|
||||
|
||||
criterion.bench_function("Batch::iteration", |b| {
|
||||
b.iter(|| batch.iteration(0, &agents))
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, criterion_benchmark);
|
||||
criterion_main!(benches);
|
||||
Reference in New Issue
Block a user