pub struct Clock { /* private fields */ }
Expand description
Unified clock for taking measurements.
Implementations§
source§impl Clock
impl Clock
sourcepub fn new() -> Clock
pub fn new() -> Clock
Creates a new clock with the optimal reference and source clocks.
Support for TSC, etc, are checked at the time of creation, not compile-time.
sourcepub fn now(&self) -> Instant
pub fn now(&self) -> Instant
Gets the current time, scaled to reference time.
This method is the spiritual equivalent of std::time::Instant::now
. It is guaranteed
to return a monotonically increasing value between calls to the same Clock
instance.
Returns an Instant
.
sourcepub fn scaled(&self, value: u64) -> Instant
pub fn scaled(&self, value: u64) -> Instant
Scales a raw measurement to reference time.
You must scale raw measurements to ensure your result is in nanoseconds. The raw measurement is not guaranteed to be in nanoseconds and may vary. It is only OK to avoid scaling raw measurements if you don’t need actual nanoseconds.
Returns an Instant
.
sourcepub fn delta_as_nanos(&self, start: u64, end: u64) -> u64
pub fn delta_as_nanos(&self, start: u64, end: u64) -> u64
sourcepub fn delta(&self, start: u64, end: u64) -> Duration
pub fn delta(&self, start: u64, end: u64) -> Duration
Calculates the delta between two raw measurements.
This method is slightly faster when you know you need the delta between two raw
measurements, or a start/end measurement, than using scaled
for both conversions.
In code that simply needs access to the whole number of nanoseconds
between the two measurements, consider Clock::delta_as_nanos
instead, which is slightly faster than having to call both this method
and Duration::as_nanos
.
sourcepub fn recent(&self) -> Instant
pub fn recent(&self) -> Instant
Gets the most recent current time, scaled to reference time.
This method provides ultra-low-overhead access to a slightly-delayed version of the current time. Instead of querying the underlying source clock directly, a shared, global value is read directly without the need to scale to reference time.
The upkeep thread must be started in order to update the time. You can read the
documentation for Upkeep
for more information on starting the upkeep thread, as
well as the details of the “current time” mechanism.
If the upkeep thread has not been started, the return value will be 0
.
Returns an Instant
.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Clock
impl RefUnwindSafe for Clock
impl Send for Clock
impl Sync for Clock
impl Unpin for Clock
impl UnwindSafe for Clock
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)