5 releases

0.1.4 Dec 10, 2019
0.1.3 Dec 9, 2019
0.1.2 Dec 8, 2019
0.1.1 Dec 8, 2019
0.1.0 Dec 8, 2019

#20 in #measure-time

Download history 4/week @ 2024-07-29 1/week @ 2024-08-05 3/week @ 2024-08-12 2/week @ 2024-08-19 39/week @ 2024-09-23 4/week @ 2024-09-30 72/week @ 2024-10-14 28/week @ 2024-10-21 42/week @ 2024-10-28 24/week @ 2024-11-04

166 downloads per month
Used in butane

MIT license

4KB
62 lines

Time measure for Rust functions

It will simply print execution time of a function

License: MIT Crates.io Build Status

Usage

[dependencies]
exec_time = "0.1.4"

Examples

In print log, it is printing Time <prefix>::<function_name>::<suffix>: <execution time> mills

Example 1

It will always print.

#[macro_use]
extern crate exec_time;

#[exec_time]
fn login() {
    std::thread::sleep(std::time::Duration::from_millis(100));
}

fn main() {
    login()
}
Time login: 102 mills

Example 2

It will print only in debug mode.

#[macro_use]
extern crate exec_time;

#[exec_time(print = "debug")]
fn login() {
    std::thread::sleep(std::time::Duration::from_millis(100));
}

fn main() {
    login()
}
Time login: 102 mills

Example 3

It will never print.

#[macro_use]
extern crate exec_time;

#[exec_time(print = "never")]
fn login() {
    std::thread::sleep(std::time::Duration::from_millis(100));
}

fn main() {
    login()
}

Example 4

It will print, prefix and suffix with function name.

#[macro_use]
extern crate exec_time;

#[exec_time(print = "always", prefix = "user/lib", suffix="route")]
fn login() {
    std::thread::sleep(std::time::Duration::from_millis(100));
}

fn main() {
    login()
}
Time user/lib::login::route: 102 mills

Note Point

Here print, prefix and suffix all are optional field. Default value of print is always. print may be always(by default), debug, never. If the value is always it will print always. If value is debug, It will print only in debug mode else, It will never print.

Dependencies

~2.5MB
~55K SLoC