Crates.io | time-elapsed |
lib.rs | time-elapsed |
version | 0.1.0 |
source | src |
created_at | 2022-12-19 21:16:27.710353 |
updated_at | 2022-12-19 21:16:27.710353 |
description | A Rust crate that provides a concise and handy way to benchmark elapsed time inside functions. |
homepage | |
repository | https://github.com/9elt/time-elapsed |
max_upload_size | |
id | 741631 |
size | 10,815 |
A Rust crate that provides a concise and handy way to benchmark elapsed time inside functions.
time-elapsed brings a small overhead, however, if you are trying to measure very small durations (in the order of nanoseconds or few microseconds), please consider using something else.
Add the following to Cargo.toml
[dependencies]
time-elapsed = "0.1.0"
use std::thread;
use std::time::Duration;
use time_elapsed;
fn main() {
let mut time = time_elapsed::start("test");
// sleep 200 ms
thread::sleep(Duration::from_millis(200));
time
.log("log() prints a message and the time elapsed")
.timestamp();
// sleep 2 ms
thread::sleep(Duration::from_millis(2));
time.log("this is an offset from the previous timestamp()");
time.log_overall("log_overall() ignores timestamps");
time.end();
}
running test... (test) log() prints a message and the time elapsed -> 200 ms (test) this is an offset from the previous timestamp() -> 2103 μs (test) log_overall() ignores timestamps -> 202 ms test finished in 202 ms (202271 μs)