log_execution_time
Overview
log_execution_time is a Rust procedural macro that logs the execution time of functions. It leverages the log crate to provide detailed timing information, making it a useful tool for performance monitoring and debugging.
Features
- Measures and logs the execution time of functions.
- Compatible with synchronous and asynchronous functions.
- Lightweight and easy to integrate into existing projects.
Installation
Add the following to your Cargo.toml file:
[]
= "0.1.0"
= "0.4" # Required for logging
Ensure you have a logger initialized in your project, such as env_logger or any other compatible logger.
Usage
Annotate your functions with #[log_execution_time]:
use log_execution_time;
Async Functions
The macro also works with asynchronous functions:
use log_execution_time;
async
async
Example
Create an example file in your project to test the macro:
Add the following to examples/main.rs:
use log_execution_time;
Run the example:
License
This project is licensed under the MIT License. See the LICENSE file for details.