Expand description
§Arbitime
A simple Rust library for timing code execution with convenient macros.
§Features
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 stderr
§Examples
§Basic timing with time!
use arbitime::time;
let (duration, result) = time! {
// Some expensive computation
(1..=1000000).sum::<u64>()
};
println!("Result: {}, took: {:?}", result, duration);§Formatted timing with format_time!
use arbitime::format_time;
let (msg, result) = format_time!("Computing sum" => {
(1..=1000).sum::<u32>()
});
println!("{}", msg); // "Computing sum - Execution time: ..."§Logging timing with log_time!
use arbitime::log_time;
// Single operation with custom message
let result = log_time!("Computing sum" => {
(1..=1000).sum::<u32>()
});
// Simple timing without custom message
log_time! {
(1..=100).sum::<u32>()
};Macros§
- format_
time - Times the execution of code blocks and formats the duration as a string.
- log_
time - Times the execution of code and automatically logs the duration to stderr.
- time
- Times the execution of a code block and returns both the duration and result.