| Crates.io | quick-timer |
| lib.rs | quick-timer |
| version | 0.1.2 |
| created_at | 2025-11-09 10:49:44.716816+00 |
| updated_at | 2025-11-13 18:38:21.00866+00 |
| description | A simple timer macro library |
| homepage | https://github.com/yyxxryrx/quick-timer |
| repository | https://github.com/yyxxryrx/quick-timer |
| max_upload_size | |
| id | 1923986 |
| size | 27,149 |
A simple Rust timer macro library for measuring execution time of code blocks.
timer! - Prints timing information to stdout (only in debug builds by default)timer_silent! - Returns timing information without printing (always active)release_also feature is enabled)Add this to your Cargo.toml:
[dependencies]
quick-timer = "0.1.0"
use quick_timer::timer;
fn main() {
timer! {
println!("Hello, world!");
}
}
use quick_timer::timer;
fn main() {
// With a tag
timer!(# "My Function" {
// Some expensive operation
std::thread::sleep(std::time::Duration::from_millis(100));
});
// Alternative syntax
timer! {
# "Another Function"
println!("Doing some work...");
}
}
use quick_timer::timer;
fn main() {
let result = timer! {
1 + 1
};
assert_eq!(result, 2);
}
use quick_timer::timer_silent;
fn main() {
let (result, duration) = timer_silent! {
println!("This will be printed");
42
};
assert_eq!(result, 42);
println!("Execution took {} ms", duration.as_millis());
}
By default, timer! macro only works in debug builds. To enable it in release builds as well, enable the release_also feature:
[dependencies]
quick-timer = { version = "0.1.0", features = ["release_also"] }
The timer! macro supports multiple syntax variants:
use quick_timer::timer;
fn main() {
// Basic form
timer! { /* code */ }
// With block syntax
timer!(block: { /* code */ });
// With tag
timer!(# "Tag" { /* code */ });
// With identifier tag
timer!(# Tag { /* code */ });
// Explicit tag syntax
timer!(tag: "Tag", block: { /* code */ });
// Braceless forms
timer! { # "Tag" /* code */ }
}
This project is licensed under either of
at your option.