Struct chroniker::Timer
[−]
[src]
pub struct Timer { pub time: Instant, }
A thin wrapper for std::time::Instant. The timer is for timing different parts of a program
Fields
time: Instant
The actual timer See std::time::Instant
Methods
impl Timer
[src]
fn new() -> Timer
fn get_elapsed(&self, unit: TimeUnit) -> u64
Similar to elapsed_millis. Gets the elapsed time in the unit passed.
Examples
use chroniker::Timer; use chroniker::units::TimeUnit; let timer = Timer::new(); chroniker::sleep(1000); let elapsed_sec = timer.get_elapsed(TimeUnit::Second); println!("Timer: {}", elapsed_sec); //Prints "1"
fn elapsed_millis(&self) -> u64
Returns the amount of milliseconds since the timer was created or reset.
Examples
use chroniker::Timer; //Create the timer let timer = Timer::new(); //Do some "operations" chroniker::sleep(1000); let elapsed_millis = timer.elapsed_millis(); println!("Timer: {}", elapsed_millis);//Prints 1000
fn reset(&mut self)
Resets thes timer to 0 and starts counting up again.
Examples
use chroniker::Timer; let mut timer = Timer::new(); chroniker::sleep(1000); let elapsed_millis = timer.elapsed_millis(); println!("Timer: {}", elapsed_millis);//Prints 1000 //Reset the timer to 0 timer.reset(); println!("Timer: {:?}", timer); //Prints 0
Trait Implementations
impl Debug for Timer
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Prints out the time.
Format
If the time is 1500 milliseconds (1.5 seconds) it will print out
$ 1.5
If the time is 75699 milliseconds (1 minute, 15 seconds, and 699 milliseconds) it will print out
$ 1:15.699
If the time is 1001 milliseconds it will print out
$ 1.001