| Crates.io | time_it |
| lib.rs | time_it |
| version | 0.1.0 |
| created_at | 2025-08-22 09:15:27.142075+00 |
| updated_at | 2025-08-22 09:15:27.142075+00 |
| description | A Rust proc macro that creates execution timing events for annotated functions via the tracing library |
| homepage | |
| repository | https://github.com/orph3usLyre/time_it |
| max_upload_size | |
| id | 1806105 |
| size | 21,108 |
A Rust procedural macro that adds execution timing to your functions. Requires the tracing library.
#[time_it] to any functionasync functionsAdd to your Cargo.toml:
[dependencies]
time_it = "0.1.0"
tracing = "0.1"
use time_it::time_it;
#[time_it] // Logs at DEBUG level by default
fn slow_computation() -> u64 {
std::thread::sleep(std::time::Duration::from_millis(100));
42
}
#[time_it]
async fn async_work() {
tokio::time::sleep(tokio::time::Duration::from_millis(50)).await;
}
#[time_it("trace")]
fn traced_function() {
// Logs execution time at TRACE level
}
#[time_it("info")]
async fn important_async_work() {
// Logs execution time at INFO level
}
#[time_it("error")]
fn critical_path() {
// Logs execution time at ERROR level
}
use time_it::time_it;
use tracing::Level;
#[tokio::main]
async fn main() {
tracing_subscriber::fmt()
.with_max_level(Level::DEBUG)
.init();
regular_work();
async_work().await;
}
#[time_it]
fn regular_work() {
println!("Doing some work...");
std::thread::sleep(std::time::Duration::from_millis(100));
}
#[time_it("info")]
async fn async_work() {
println!("Doing async work...");
tokio::time::sleep(tokio::time::Duration::from_millis(50)).await;
}
Licensed under either of Apache License, Version 2.0 or MIT license at your option.