#[cfg(not(target_arch = "wasm32"))]
use std::time::SystemTime;
#[must_use]
#[cfg(target_arch = "wasm32")]
pub(crate) fn performance_counter(counter_type: u32) -> u64 {
ic_cdk::api::performance_counter(counter_type)
}
#[must_use]
#[cfg_attr(
not(target_arch = "wasm32"),
expect(
clippy::cast_possible_truncation,
reason = "millisecond epoch values fit into u64 for IcyDB timestamps"
)
)]
pub(crate) fn now_millis() -> u64 {
#[cfg(target_arch = "wasm32")]
{
ic_cdk::api::time() / 1_000_000
}
#[cfg(not(target_arch = "wasm32"))]
{
match SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) {
Ok(duration) => duration.as_millis() as u64,
Err(_) => 0,
}
}
}