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
impl SimpleTimer
sourcepub fn start_after(&mut self, dur: &Duration)
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.
sourcepub fn time_in_nanos(&self) -> Option<u128>
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
sourcepub fn time_in_micros(&self) -> Option<u128>
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
sourcepub fn time_in_millis(&self) -> Option<u128>
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
sourcepub fn time_in_secs(&self) -> Option<u64>
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