Struct quanta::Clock

source ·
pub struct Clock { /* private fields */ }
Expand description

Unified clock for taking measurements.

Implementations§

source§

impl Clock

source

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.

source

pub fn mock() -> (Clock, Arc<Mock>)

Creates a new clock that is mocked for controlling the underlying time.

Returns a Clock instance and a handle to the underlying Mock source so that the caller can control the passage of time.

source

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.

source

pub fn raw(&self) -> u64

Gets the underlying time from the fastest available clock source.

As the clock source may or may not be the TSC, value is not guaranteed to be in nanoseconds or to be monotonic. Value can be scaled to reference time by calling either scaled or delta.

source

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.

source

pub fn delta_as_nanos(&self, start: u64, end: u64) -> u64

Calculates the delta, in nanoseconds, between two raw measurements.

This method is very similar to delta but reduces overhead for high-frequency measurements that work with nanosecond counts internally, as it avoids the conversion of the delta into Duration.

source

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.

source

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§

source§

impl Clone for Clock

source§

fn clone(&self) -> Clock

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Clock

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Clock

source§

fn default() -> Clock

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.