Skip to main content

Crate exec_time

Crate exec_time 

Source
Expand description

exec_time provides an attribute macro for timing sync and async functions.

It is intended for lightweight instrumentation during development and debugging.

§Default

use exec_time::exec_time;

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

Output:

[exec_time] login took 102 ms

§Common Options

  • print = "always" | "debug" | "never"
  • name = "..."
  • prefix = "...", suffix = "..."
  • unit = "ns" | "us" | "ms" | "s"
  • log_over = "500us" | "5ms" | "0.5s"
  • warn_over = "500us" | "5ms" | "0.5s"

name overrides the generated function label. warn_over takes precedence over log_over when both thresholds match.

§Thresholds

use exec_time::exec_time;

#[exec_time(name = "db.query", warn_over = "250ms")]
fn query_db() {
    std::thread::sleep(std::time::Duration::from_millis(300));
}

Output:

[exec_time][warn] db.query took 300 ms

§Notes

  • Works with sync and async functions
  • Preserves generics, return values, and where clauses
  • print = "never" disables all output

Attribute Macros§

exec_time
Measure the execution time of a function.