5 releases

✓ Uses Rust 2018 edition

new 0.2.1 Mar 23, 2020
0.2.0 Mar 23, 2020
0.1.2 Feb 27, 2020
0.1.1 Feb 27, 2020
0.1.0 Feb 27, 2020
Download history 50/week @ 2020-02-22 30/week @ 2020-02-29 72/week @ 2020-03-07 53/week @ 2020-03-14

82 downloads per month

Custom license

4KB

Micro-timer

This crate exposes a simple procedural macro that logs you how much time was spent during each call of the function it wraps.

Installing

In Cargo.toml:

[dependencies]
micro-timer = "0.2.1"
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.

Usage

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();
}

Result

$ RUST_LOG=trace ./my-program
2020-02-27 14:27:01,097 TRACE [my_crate::my_module] Duration of `my_func`: 2.024734ms

Dependencies

~465–780KB
~18K SLoC