clay-borg/games/ground/benches/synthetic.rs

49 lines
1.9 KiB
Rust

//! Criterion skeleton for AM-6/AM-7 (GameKernel §4), wired to the
//! CB-RES-0001 baseline shape (3-player commit/reveal synthetic workload).
//! T08 replaces the placeholder body with the real aggregate loop; the
//! bench IDs and workload sizes are fixed here so results stay comparable
//! to benchmarks/baselines/ recordings.
use cb_events::state_hash;
use cb_game_runtime::CommitWindow;
use cb_kernel::PlayerId;
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
/// Placeholder workload: open/submit/reveal one 3-player commit window and
/// hash a small value. Exists so the bench harness, IDs, and baseline
/// wiring compile and run before the aggregate exists.
fn commit_reveal_round() -> usize {
let mut w: CommitWindow<u8> = CommitWindow::open([PlayerId(0), PlayerId(1), PlayerId(2)]);
for p in 0..3u8 {
w.submit(PlayerId(p), p).unwrap();
}
let revealed = w.reveal().unwrap();
state_hash(&revealed.len()).len()
}
fn bench_synthetic(c: &mut Criterion) {
let mut group = c.benchmark_group("synthetic-ground-3p");
// AM-6 headline workload sizes; AM-7 compares 5k vs 100k throughput.
for &rounds in &[5_000usize, 100_000] {
group.bench_function(format!("commit-reveal-{rounds}"), |b| {
b.iter_batched(
|| rounds,
|n| {
let mut acc = 0usize;
for _ in 0..n / 1000 {
// Scaffold runs 1/1000th scale until T08 wires the
// real aggregate; the group/ID layout is what T07
// delivers.
acc += commit_reveal_round();
}
acc
},
BatchSize::SmallInput,
)
});
}
group.finish();
}
criterion_group!(benches, bench_synthetic);
criterion_main!(benches);