Struct devtimer::SimpleTimer

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

The SimpleTimer struct holds the start and stop time instances

Implementations§

source§

impl SimpleTimer

source

pub fn new() -> Self

Returns a new instance of the DevTime struct

source

pub fn start(&mut self)

Starts a timer on a mutable DevTime object

source

pub fn stop(&mut self)

Stops a timer on a mutable DevTime object

source

pub fn start_after(&mut self, dur: &Duration)

Starts a timer after a specified duration

Example
use devtimer::DevTime;
use std::time::Duration;
fn main() {
    let mut timer = DevTime::new_simple();
    timer.start_after(&Duration::from_secs(2));
    // The timer will automatically start after two seconds
    // do_some_long_operation();
    timer.stop();
    println!("Time taken: {}", timer.time_in_secs().unwrap());
    // The timer can be reused normally again
    timer.start(); // this starts the timer instantly
    // do_another_long_operation();
    timer.stop();
    println!("Time taken: {}", timer.time_in_secs().unwrap());
}
Important Note

This will try to be as precise as possible. However exact precision cannot be guranteed. As tested on multiple platforms, there are variations in the range of 0 to 10 nanoseconds.

source

pub fn time_in_nanos(&self) -> Option<u128>

Returns an Option<u128> with the difference from the starting time that was created with start() and the stop time that was created with stop(). If both the fields exist, then the time difference is returned in nanoseconds, otherwise None is returned

source

pub fn time_in_micros(&self) -> Option<u128>

Returns an Option<u128> with the difference from the starting time that was created with start() and the stop time that was created with stop(). If both the fields exist, then the time difference is returned in microseconds, otherwise None is returned

source

pub fn time_in_millis(&self) -> Option<u128>

Returns an Option<u128> with the difference from the starting time that was created with start() and the stop time that was created with stop(). If both the fields exist, then the time difference is returned in milliseconds, otherwise None is returned

source

pub fn time_in_secs(&self) -> Option<u64>

Returns an Option<u64> with the difference from the starting time that was created with start() and the stop time that was created with stop(). If both the fields exist, then the time difference is returned in seconds, otherwise None is returned

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.