From db46d6dd6b5db90b26302749df6ed99bc0404756 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 3 Jul 2024 19:13:49 +0000 Subject: [PATCH] optimize millis_since_unix_epoch() Signed-off-by: Jason Volk --- src/core/utils/mod.rs | 2 +- src/core/utils/time.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/utils/mod.rs b/src/core/utils/mod.rs index 75f55c9a..b34611df 100644 --- a/src/core/utils/mod.rs +++ b/src/core/utils/mod.rs @@ -23,7 +23,7 @@ pub use mutex_map::MutexMap; pub use rand::string as random_string; pub use string::{str_from_bytes, string_from_bytes}; pub use sys::available_parallelism; -pub use time::millis_since_unix_epoch; +pub use time::now_millis as millis_since_unix_epoch; use crate::Result; diff --git a/src/core/utils/time.rs b/src/core/utils/time.rs index d7cab1fb..f6208b31 100644 --- a/src/core/utils/time.rs +++ b/src/core/utils/time.rs @@ -1,12 +1,12 @@ -use std::time::{SystemTime, UNIX_EPOCH}; - #[inline] #[must_use] #[allow(clippy::as_conversions)] -pub fn millis_since_unix_epoch() -> u64 { - SystemTime::now() - .duration_since(UNIX_EPOCH) - .expect("time is valid") +pub fn now_millis() -> u64 { + use std::time::UNIX_EPOCH; + + UNIX_EPOCH + .elapsed() + .expect("positive duration after epoch") .as_millis() as u64 }