[−][src]Struct devtimer::SimpleTimer
The SimpleTimer
struct holds the start and stop time instances
Implementations
impl SimpleTimer
[src]
pub fn new() -> Self
[src]
Returns a new instance of the DevTime
struct
pub fn start(&mut self)
[src]
Starts a timer on a mutable DevTime
object
pub fn stop(&mut self)
[src]
Stops a timer on a mutable DevTime
object
pub fn start_after(&mut self, dur: &Duration)
[src]
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.
pub fn time_in_nanos(&self) -> Option<u128>
[src]
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
pub fn time_in_micros(&self) -> Option<u128>
[src]
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
pub fn time_in_millis(&self) -> Option<u128>
[src]
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
pub fn time_in_secs(&self) -> Option<u64>
[src]
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
impl RefUnwindSafe for SimpleTimer
[src]
impl Send for SimpleTimer
[src]
impl Sync for SimpleTimer
[src]
impl Unpin for SimpleTimer
[src]
impl UnwindSafe for SimpleTimer
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,