took
: easily measure & report elapsed time
I 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.
Examples
-
Measure & report manually using Timer stopwatch:
use Timer; let timer = new; // Run heavy task println!; // Prints: // Done! Took 1.00 s
-
Measure a function, report manually:
use took; let = took; println!; // Prints: // Done! Took 1.00 s
-
Measure & report a function automatically using attribute:
extern crate took_macro; my_function; other_function; // Prints: // my_function() took 1.00 s // Render finished, took 1.00 s
Requirements
- Rust 1.33 or newer (with
std
)
Usage
Add the dependencies in your Cargo.toml
. The took-macro
dependency is only
required if you'll be using the #[took]
attribute macro.
[]
= "0.1"
= "0.1" # if using macros
Import and start using:
use ;
let timer = new;
println!;
let = took;
println!;
If you'll be using #[took]
attribute macro, explicitly import it:
extern crate took_macro;
TODO
- Support
#[took]
attribute for almost anything (function call, blocks, if-statements, ...) - Time formatting configurability
- Use more precise timers
- Print elapsed time to more than just
stderr
License
This project is released under the MIT license. Check out the LICENSE file for more information.