//! One slice's event sweep. //! //! Written against the public API rather than against `TimeSlice` directly. //! It used to reach for `TimeSlice`, `KeyTable`, `CompetitorStore`, //! `Competitor` and `EventKind`, and was the *only* thing outside `src/` //! that did — so a benchmark was dictating five public types that no test, //! example or consumer could otherwise obtain. //! //! A single-slice history's `converge` calls exactly the same per-slice sweep, //! so capping at one iteration measures the same code path. use criterion::{Criterion, criterion_group, criterion_main}; use smallvec::smallvec; use trueskill_tt::{ ConstantDrift, ConvergenceOptions, Event, History, Member, Outcome, Team, }; fn criterion_benchmark(criterion: &mut Criterion) { let build = || { let mut h = History::builder() .convergence(ConvergenceOptions { max_iter: 1, epsilon: 0.0, alpha: 1.0, }) .drift(ConstantDrift::new(0.0)) .build(); // 100 events, all at one time, so the history has a single slice. let events: Vec> = (0..100) .map(|_| Event { time: 1, teams: smallvec![ Team::with_members([Member::new("a")]), Team::with_members([Member::new("b")]), ], outcome: Outcome::winner(0, 2), }) .collect(); h.add_events(events).expect("fixture ingests"); h }; criterion.bench_function("slice_sweep_100_events", |b| { b.iter_batched( build, |mut h| { // `converge_partial`, not `converge`: one iteration is // deliberately short of convergence and `converge` reports that // as an error. let _ = h.converge_partial(); }, criterion::BatchSize::SmallInput, ); }); } criterion_group!(benches, criterion_benchmark); criterion_main!(benches);