Skip to main content

luaur_analysis/functions/
get_timestamp.rs

1pub fn get_timestamp() -> f64 {
2    // `wasm32-unknown-unknown` has no clock backend: `std::time::SystemTime::now`
3    // panics there ("time not implemented on this platform"). This timestamp is
4    // only used for the type checker's timing instrumentation (analogous to the
5    // `TimeTrace` no-ops), not for any correctness decision, so on wasm it
6    // reports a fixed value instead of panicking.
7    #[cfg(target_arch = "wasm32")]
8    {
9        0.0
10    }
11
12    #[cfg(not(target_arch = "wasm32"))]
13    {
14        let now = std::time::SystemTime::now();
15        let duration = now
16            .duration_since(std::time::UNIX_EPOCH)
17            .unwrap_or_else(|e| e.duration());
18        duration.as_secs_f64()
19    }
20}