Crates.io | simple-stopwatch |
lib.rs | simple-stopwatch |
version | 0.1.4 |
source | src |
created_at | 2018-01-21 22:03:31.273959 |
updated_at | 2018-01-21 23:22:35.190682 |
description | Minimal stopwatch for rust, returns float values |
homepage | https://github.com/huwb/rust-simple-stopwatch |
repository | https://github.com/huwb/rust-simple-stopwatch |
max_upload_size | |
id | 47706 |
size | 6,149 |
A minimal no-thrills stopwatch. Returns time values as floats. Uses time::precise_time_ns
under the hood.
Add the dependency simple-stopwatch
to your Cargo.toml
file, for example:
[dependencies]
simple-stopwatch="0.1.4"
Then import the stopwatch anywhere you would like to use it:
extern crate simple_stopwatch;
use simple_stopwatch::Stopwatch;
There is minimal state in simple-stopwatch
. Upon creation it grabs a timestamp, from which point its member functions will return elapsed time.
fn my_function() {
let sw = Stopwatch::start_new();
do_some_heavy_work();
let elapsed_ms = sw.ms();
println!("Time taken: {}ms", elapsed_ms);
}
The restart
method updates the stored timestamp to the current time.
The code make use of a small amount of code from the time
crate, which uses a system call to obtain a high precision time stamp. The overhead of this call appears to be very small from my experiments so far.