| Crates.io | arbitime |
| lib.rs | arbitime |
| version | 0.1.2 |
| created_at | 2025-07-30 07:51:00.211948+00 |
| updated_at | 2025-08-01 19:43:26.454479+00 |
| description | Dead simple timing macros |
| homepage | |
| repository | https://github.com/rtificr/arbitime |
| max_upload_size | |
| id | 1773222 |
| size | 16,815 |
A simple Rust library for timing code execution with convenient macros.
time! - Time code execution and return both duration and resultformat_time! - Time code execution and format duration as a stringlog_time! - Time code execution with automatic logging to stderrtime!use arbitime::time;
let (duration, result) = time! {
// Some expensive computation
(1..=1000000).sum::<u64>()
};
println!("Result: {}, took: {:?}", result, duration);
format_time!use arbitime::format_time;
// Single operation with custom message
let (msg, result) = format_time!("Computing sum" => {
(1..=1000).sum::<u32>()
});
println!("{}", msg); // "Computing sum - Execution time: 42.123µs"
// Simple timing without custom message
let (msg, result) = format_time! {
expensive_operation()
};
println!("{}", msg); // "Execution time: 1.234ms"
log_time!use arbitime::log_time;
// Single operation with custom message
let result = log_time!("Computing sum" => {
(1..=1000).sum::<u32>()
});
// Prints: "Computing sum - Execution time: 42.123µs"
// Simple timing without custom message
let result = log_time! {
expensive_operation()
};
// Prints: "Execution time: 1.234ms"
time!Times the execution of a code block and returns both the duration and result as a tuple (Duration, T).
format_time!Times the execution of a code block and returns a formatted timing message along with the result as a tuple (String, T). The string contains a human-readable timing message.
log_time!Times the execution of code and automatically logs the duration to stderr, returning only the result. This is a convenience wrapper around format_time! that handles the logging automatically.
All timing information is printed to stderr using eprintln!.
This project is licensed under the MIT License.