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
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Usage
Basic timing with time!
use time;
let = time! ;
println!;
Formatted timing with format_time!
use format_time;
// Single operation with custom message
let = format_time!;
println!; // "Computing sum - Execution time: 42.123µs"
// Simple timing without custom message
let = format_time! ;
println!; // "Execution time: 1.234ms"
Automatic logging with log_time!
use log_time;
// Single operation with custom message
let result = log_time!;
// Prints: "Computing sum - Execution time: 42.123µs"
// Simple timing without custom message
let result = log_time! ;
// Prints: "Execution time: 1.234ms"
API Reference
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!.
License
This project is licensed under the MIT License.