Competitor holds dynamic per-history state (message, last_time) for someone competing; its configuration lives in a Rating. AgentStore renamed to CompetitorStore to match. The internal `clean()` free function's parameter name changed from `agents` to `competitors` for consistency. Local variable names (agent_idx, this_agent) inside history.rs are left unchanged — they represent abstract identifiers, not Competitor instances. Part of T2 of docs/superpowers/specs/2026-04-23-trueskill-engine-redesign-design.md.
46 lines
1.3 KiB
Rust
46 lines
1.3 KiB
Rust
use criterion::{Criterion, criterion_group, criterion_main};
|
|
use trueskill_tt::{
|
|
BETA, Competitor, GAMMA, KeyTable, MU, P_DRAW, Rating, SIGMA, batch::Batch,
|
|
drift::ConstantDrift, gaussian::Gaussian, storage::CompetitorStore,
|
|
};
|
|
|
|
fn criterion_benchmark(criterion: &mut Criterion) {
|
|
let mut index_map = KeyTable::new();
|
|
|
|
let a = index_map.get_or_create("a");
|
|
let b = index_map.get_or_create("b");
|
|
let c = index_map.get_or_create("c");
|
|
|
|
let mut agents: CompetitorStore<ConstantDrift> = CompetitorStore::new();
|
|
|
|
for agent in [a, b, c] {
|
|
agents.insert(
|
|
agent,
|
|
Competitor {
|
|
rating: Rating::new(Gaussian::from_ms(MU, SIGMA), BETA, ConstantDrift(GAMMA)),
|
|
..Default::default()
|
|
},
|
|
);
|
|
}
|
|
|
|
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(1, P_DRAW);
|
|
batch.add_events(composition, results, weights, &agents);
|
|
|
|
criterion.bench_function("Batch::iteration", |b| {
|
|
b.iter(|| batch.iteration(0, &agents))
|
|
});
|
|
}
|
|
|
|
criterion_group!(benches, criterion_benchmark);
|
|
criterion_main!(benches);
|