//! Phase timings on stderr when `CVERIF_TIMING` is set: where a run's wall time goes.
use std::sync::Mutex;
use std::sync::OnceLock;
use std::time::Instant;
static LAST: Mutex<Option<Instant>> = Mutex::new(None);
fn enabled() -> bool {
static ON: OnceLock<bool> = OnceLock::new();
*ON.get_or_init(|| std::env::var_os("CVERIF_TIMING").is_some())
}
/// The time since the previous mark (or since the first call) is attributed to `phase`.
pub fn mark(phase: &str) {
if !enabled() {
return;
}
let now = Instant::now();
let mut last = LAST.lock().unwrap();
if let Some(t) = *last {
eprintln!("timing: {:>8.3} s {phase}", (now - t).as_secs_f64());
}
*last = Some(now);
}