Crates.io | stopwatch2 |
lib.rs | stopwatch2 |
version | 2.0.0 |
source | src |
created_at | 2021-04-30 17:04:27.877318 |
updated_at | 2021-04-30 17:04:27.877318 |
description | A stopwatch library for timing things. A rewrite and simplification of the original stopwatch crate. |
homepage | |
repository | https://github.com/jojolepro/rust-stopwatch |
max_upload_size | |
id | 391619 |
size | 10,923 |
Support an Open Source Developer! :hearts:
Read the documentation.
This crate is a simplified version of the work of ellisonch.
Add the following to you Cargo.toml file:
stopwatch2 = "*"
Use the stopwatch like so:
use stopwatch2::*;
fn main() {
let mut s = Stopwatch::default();
s.start(); // Starts the stopwatch.
s.start(); // Creates a new time span, which are commonly called "splits".
s.stop(); // Stops the stopwatch.
println!("{}", s); // Prints the total time.
println!("{:?}", s); // Prints the different time spans as debug information.
let total_time = s.elapsed(); // returns the total time as a Duration.
for span in &s.spans {
// Prints all contained time spans.
println!("{:?} -> {:?}", span.start, span.stop);
}
s.spans.clear(); // Reset the stopwatch.
println!("{}", s); // Prints the total time.
println!("{:?}", s); // Prints the different time spans as debug information.
}