pub fn now_secs() -> u64 {
#[cfg(not(target_arch = "wasm32"))]
{
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_default()
.as_secs()
}
#[cfg(target_arch = "wasm32")]
{
0
}
}
pub fn now_millis() -> u64 {
#[cfg(not(target_arch = "wasm32"))]
{
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_default()
.as_millis() as u64
}
#[cfg(target_arch = "wasm32")]
{
0
}
}
#[derive(Debug, Clone, Copy)]
pub struct Timer {
#[cfg(not(target_arch = "wasm32"))]
start: std::time::Instant,
}
impl Timer {
pub fn now() -> Self {
Self {
#[cfg(not(target_arch = "wasm32"))]
start: std::time::Instant::now(),
}
}
pub fn elapsed_ms(&self) -> u64 {
#[cfg(not(target_arch = "wasm32"))]
{
self.start.elapsed().as_millis() as u64
}
#[cfg(target_arch = "wasm32")]
{
0
}
}
pub fn elapsed(&self) -> std::time::Duration {
#[cfg(not(target_arch = "wasm32"))]
{
self.start.elapsed()
}
#[cfg(target_arch = "wasm32")]
{
std::time::Duration::ZERO
}
}
}