use prometeu_drivers::ControlledWallClock; use prometeu_hal::WallClock; use prometeu_host_desktop_winit::wall_clock::SystemWallClock; use std::hint::black_box; use std::time::Instant; fn measure(name: &str, clock: &dyn WallClock) { const BATCHES: usize = 101; const READS: usize = 10_000; for _ in 0..READS { black_box(black_box(clock).utc_unix_seconds()); } let mut samples = Vec::with_capacity(BATCHES); for _ in 0..BATCHES { let start = Instant::now(); for _ in 0..READS { black_box(black_box(clock).utc_unix_seconds()); } samples.push(start.elapsed().as_nanos() as f64 / READS as f64); } samples.sort_by(f64::total_cmp); println!( "{name}: batches={BATCHES} reads_per_batch={READS} ns/read batch_mean p50={:.2} p95={:.2} max={:.2}", samples[50], samples[95], samples[100] ); } fn main() { println!( "target={}-{} debug_assertions={}; batch means include dynamic dispatch and loop overhead", std::env::consts::ARCH, std::env::consts::OS, cfg!(debug_assertions) ); measure("system", &SystemWallClock); measure("controlled", &ControlledWallClock::new(1_000)); }