rust_css_parser/utils/
time.rs1#[cfg(not(target_arch = "wasm32"))]
4pub fn now() -> f64 {
5 use std::sync::OnceLock;
6 use std::time::Instant;
7 static START: OnceLock<Instant> = OnceLock::new();
8 START.get_or_init(Instant::now).elapsed().as_secs_f64() * 1000.0
9}
10
11#[cfg(target_arch = "wasm32")]
12pub fn now() -> f64 {
13 #[link(wasm_import_module = "env")]
14 extern "C" {
15 fn css_now() -> f64;
16 }
17 unsafe { css_now() }
19}
20
21pub fn format_ms(ms: f64) -> String {
23 format!("{}ms", crate::utils::number::to_fixed(ms, 2))
24}