1 unstable release
0.1.0 | Aug 22, 2021 |
---|
#10 in #measuring
12KB
147 lines
calculagraph
A handy library for measuring the execution time of function.
Usage
[dependencies]
calculagraph = "0.1"
use std::{thread, time};
use calculagraph::timer_println;
#[timer_println(ms)]
fn main() {
thread::sleep(time::Duration::from_millis(10));
println!("job done");
}
The above example will print fn:main cost 10ms
at the end, You can also use the second
argument to define the format string you need.
More
lib.rs
:
A handy library for measuring the execution time of function.
Use
The use of the crate is through the 4 attribute macros:
#[timer_println]
, #[timer_log_trace]
, #[timer_log_info]
, #[timer_log_debug]
.
Just like the name they have, timer_println
means that it will be using the macro println!
to
print the results, while timer_log_trace
, timer_log_info
and timer_log_debug
respectively
using macros log::trace!
, log::info!
and log::debug!
to output.
Of course, when using the last 3 macros, you should link the log facade and its implementation.
Examples
[dependencies]
calculagraph = "0.1"
use std::{thread, time};
use calculagraph::timer_println;
#[timer_println(ms)]
fn main() {
thread::sleep(time::Duration::from_millis(10));
println!("job done");
}
The above example will print fn:main cost 10ms
at the end, You can also use the second
argument to define the format string you need.
Note
This macro added two variables that would never conflict in ordinary business, they are
now_x7bf707c839bc2554fa3f1913a8dc699b68236726c5da18b31f660948ca7f542a267de9b
and
result_x7bf707c839bc2554fa3f1913a8dc699b68236726c5da18b31f660948ca7f542a267de9b
, just don't
use them intentionally.
Dependencies
~1.5MB
~35K SLoC