[−][src]Struct devtimer::DevTime
The DevTime
struct provides a simple implementation
for timing operations using the standard library
Methods
impl DevTime
[src]
pub fn new() -> DevTime
[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; use std::time::Duration; let mut timer = DevTime::new(); timer.start_after(Duration::from_secs(2)); // The timer will automatically start after two seconds do_some_long_operation(); 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 Send for DevTime
impl Sync for DevTime
impl Unpin for DevTime
impl UnwindSafe for DevTime
impl RefUnwindSafe for DevTime
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
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.
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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,