Struct time_elapsed::TimeElapsed
source · pub struct TimeElapsed { /* private fields */ }
Expand description
Stores the benchmark state and provides methods (timestamp method needs a mutable reference).
To create an initialized instance use the time_elapsed::start function.
example
let mut time = time_elapsed::start("test");
// output: running test...
Implementations§
source§impl TimeElapsed
impl TimeElapsed
sourcepub fn end(self)
pub fn end(self)
Ends the benchmark. Outputs the total elapsed time from the start of the benchmark.
example
let mut time = time_elapsed::start("test");
// output: running test...
time.end();
// output: test finished in 1 μs (1204 ns)
sourcepub fn log<S: AsRef<str>>(&mut self, msg: S) -> &mut Self
pub fn log<S: AsRef<str>>(&mut self, msg: S) -> &mut Self
Outputs a message followed by the elapsed time from the previous timestamp.
Returns a mutable reference of self.
example
let mut time = time_elapsed::start("test");
// output: running test...
time.log("My message");
// output: (test) My message -> 1 μs
sourcepub fn log_overall<S: AsRef<str>>(&mut self, msg: S) -> &mut Self
pub fn log_overall<S: AsRef<str>>(&mut self, msg: S) -> &mut Self
Outputs a message followed by the elapsed time from the start, ignoring timestamps.
Returns a mutable reference of self.
example
use std::thread;
use std::time::Duration;
let mut time = time_elapsed::start("test");
// output: running test...
thread::sleep(Duration::from_millis(200));
time.timestamp();
time.log_overall("The elapsed time from the start");
// output: (test) The elapsed time from the start -> 200 ms
sourcepub fn timestamp(&mut self) -> Instant
pub fn timestamp(&mut self) -> Instant
Updates and returns the last timestamp.
example
use std::thread;
use std::time::Duration;
let mut time = time_elapsed::start("test");
// output: running test...
thread::sleep(Duration::from_millis(200));
time.timestamp();
time.log("Elapsed time from the prev timestamp");
// output: (test) Elapsed time from the prev timestamp -> 1 μs
Trait Implementations§
source§impl Clone for TimeElapsed
impl Clone for TimeElapsed
source§fn clone(&self) -> TimeElapsed
fn clone(&self) -> TimeElapsed
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for TimeElapsed
impl Debug for TimeElapsed
source§impl Hash for TimeElapsed
impl Hash for TimeElapsed
source§impl Ord for TimeElapsed
impl Ord for TimeElapsed
source§fn cmp(&self, other: &TimeElapsed) -> Ordering
fn cmp(&self, other: &TimeElapsed) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl PartialEq<TimeElapsed> for TimeElapsed
impl PartialEq<TimeElapsed> for TimeElapsed
source§fn eq(&self, other: &TimeElapsed) -> bool
fn eq(&self, other: &TimeElapsed) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<TimeElapsed> for TimeElapsed
impl PartialOrd<TimeElapsed> for TimeElapsed
source§fn partial_cmp(&self, other: &TimeElapsed) -> Option<Ordering>
fn partial_cmp(&self, other: &TimeElapsed) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read more