Crates.io | micro-timer |
lib.rs | micro-timer |
version | 0.4.0 |
source | src |
created_at | 2020-02-27 14:31:49.131258 |
updated_at | 2020-09-28 13:40:49.59303 |
description | Dumb tiny logging timer |
homepage | https://foss.heptapod.net/octobus/rust/micro-timer |
repository | https://foss.heptapod.net/octobus/rust/micro-timer |
max_upload_size | |
id | 213112 |
size | 7,312 |
This crate exposes a simple procedural macro that logs you how much time was spent during each call of the function it wraps.
In Cargo.toml
:
[dependencies]
micro-timer = "0.4.0"
log = "0.4.8"
The community-standard log
crate is used for output. In reality, since procedural macros don't have hygiene, you could define log
as being anything that has the same interface as the log
crate.
use micro_timer::timed;
/// Expose the `log` crate as `crate::log`.
use log;
#[timed]
fn my_func() {
// code here
}
fn main() {
// Use any standard logger you want.
// In this case, we're using `simple_logger`
simple_logger::init_by_env();
}
$ RUST_LOG=trace ./my-program
2020-02-27 14:27:01,097 TRACE [my_crate::my_module] Duration of `my_func`: 2.024734ms
The minimum supported Rust version is 1.41.1
, because it's whatever Debian stable has. It probably works in older versions, but it's not guaranteed.