pool_lat/pool_lat.rs
1//! Pool dispatch-latency probe (scratch diagnostic, not a product).
2//!
3//! Times `Pool::run` with an empty closure: the pure cost of waking every
4//! worker and collecting the latch. Decode issues one dispatch per matvec
5//! (~200/token), so this cost is paid ~200 times per token — compare it
6//! against the per-worker work of a typical MLP row-slice.
7//!
8//! Usage: cargo run --release --example pool_lat
9
10use cortiq_engine::pool::Pool;
11use std::time::Instant;
12
13fn main() {
14 for nt in [2usize, 4, 6, 8, 10] {
15 let pool = Pool::new(nt);
16 let noop: &(dyn Fn(usize, usize) + Sync) = &|_w, _n| {};
17 // Warm: first dispatch spawns/parks the workers.
18 for _ in 0..100 {
19 pool.run(noop);
20 }
21 let iters = 20_000;
22 let t0 = Instant::now();
23 for _ in 0..iters {
24 pool.run(noop);
25 }
26 let el = t0.elapsed().as_secs_f64();
27 let per = el / iters as f64 * 1e6;
28 println!(
29 "threads={nt:2} {per:7.2} us/dispatch -> {:6.2} ms/token at 200 matvecs",
30 per * 200.0 / 1e3
31 );
32 }
33}