| Crates.io | took |
| lib.rs | took |
| version | 0.1.2 |
| created_at | 2019-09-30 19:31:53.414348+00 |
| updated_at | 2019-10-13 16:28:08.810036+00 |
| description | Easily measure & report elapsed time |
| homepage | https://gitlab.com/timvisee/took-rs |
| repository | https://gitlab.com/timvisee/took-rs |
| max_upload_size | |
| id | 168889 |
| size | 11,383 |
took: easily measure & report elapsed timeI always find measuring and reporting run time of code it in a human readable format troublesome.
This crate provides a few simple interfaces to do just that.
Measure & report manually using Timer stopwatch:
use took::Timer;
let timer = Timer::new();
// Run heavy task
println!("Done! Took {}", timer.took());
// Prints:
// Done! Took 1.00 s
Measure a function, report manually:
use took::took;
let (took, result) = took(|| {
// Run heavy task
});
println!("Done, took {}", took);
// Prints:
// Done! Took 1.00 s
Measure & report a function automatically using attribute:
#[macro_use]
extern crate took_macro;
my_function();
other_function();
#[took]
pub fn my_function() {
// Run heavy task
}
#[took(description = "Render finished,")]
pub fn other_function() {
// Run heavy task
}
// Prints:
// my_function() took 1.00 s
// Render finished, took 1.00 s
std)Add the dependencies in your Cargo.toml. The took-macro dependency is only
required if you'll be using the #[took] attribute macro.
[dependencies]
took = "0.1"
took-macro = "0.1" # if using macros
Import and start using:
use took::{Timer, took};
let timer = Timer::new();
println!("Done! Took {}", timer.took());
let (took, result) = took(|| {
// Run heavy task
});
println!("Done, took {}", took);
If you'll be using #[took] attribute macro, explicitly import it:
#[macro_use]
extern crate took_macro;
#[took]
pub fn function_one() {}
#[took(description = "Some heavy logic finished,")]
pub fn function_two() {}
#[took] attribute for almost anything
(function call, blocks, if-statements, ...)stderrThis project is released under the MIT license. Check out the LICENSE file for more information.