use std::time::Duration;
#[derive(Clone, Copy, Debug)]
pub(crate) struct Stopwatch {
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
start: std::time::Instant,
}
impl Stopwatch {
#[inline]
pub(crate) fn start() -> Stopwatch {
Stopwatch {
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
start: std::time::Instant::now(),
}
}
#[inline]
pub(crate) fn elapsed(self) -> Duration {
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
return self.start.elapsed();
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
return Duration::ZERO;
}
}
pub(crate) fn time_seed() -> u64 {
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
return std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map_or(1, |elapsed| elapsed.as_nanos() as u64);
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
return 1;
}