specfold-core 0.3.0

Library behind specfold: typed Markdown documents, owners, a derived graph and checks.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//! Phase timings on stderr when `SPECFOLD_TRACE` is set, for diagnosing slow runs.

use std::sync::OnceLock;
use std::time::Instant;

fn enabled() -> bool {
    static ON: OnceLock<bool> = OnceLock::new();
    *ON.get_or_init(|| std::env::var_os("SPECFOLD_TRACE").is_some())
}

/// Prints how long a phase took since `start` and returns a new start.
pub fn phase(name: &str, start: Instant) -> Instant {
    if enabled() {
        eprintln!("specfold: {name:<12} {:>7.1} ms", start.elapsed().as_secs_f64() * 1000.0);
    }
    Instant::now()
}