Slow Function Warning
This crate provides a procedural macro to inject timers into functions and print a warning if it takes longer than expected. It can be particularly useful for debugging performance issues during development.
Conditional Compilation
Timing functions can affect the performance of your application, so it's important to use conditional compilation to ensure that the timing code is only included when necessary.
debug_slow_function_warning // in debug mode
release_slow_function_warning // in release mode
slow_function_warning // in both debug and release mode
Usage
Installation
Add the following to your Cargo.toml
:
[]
= "0.1.0"
Basic Example
// Warn if the function takes longer than 1000 milliseconds
Custom Message Example
// Warn if the function takes longer than 1000 milliseconds with a custom message
Duration Syntax
You can specify the duration using numeric literals followed by a suffix:
ns
for nanosecondsms
for millisecondss
for secondsm
for minutesh
for hoursd
for days
Available Variables
module: String
- The name of the modulefunction: String
- The name of the functionelapsed: Duration
- The elapsed timenanos: u64
- The elapsed time in nanosecondsns: u64
- The elapsed time in nanosecondsmillis: u64
- The elapsed time in millisecondsms: u64
- The elapsed time in millisecondssecs: u64
- The elapsed time in secondss: u64
- The elapsed time in seconds