Tea Timer
Tea Timer is a simple and efficient Rust library for measuring and reporting the duration of tasks. It provides an easy-to-use API for creating timers, measuring elapsed time, and formatting durations.
Features
- Create named timers
- Measure elapsed time
- Format durations in a human-readable format
- Restart timers with new task names
- Optional logging support using the
logcrate
Installation
Add this to your Cargo.toml:
= "0.1.0"
Usage
Macro Usage
let result = took! ;
// this will print elapsed time and get result of thecode block
Function Usage
use took;
let result = took;
// this will print elapsed time and get result of the function
Basic Usage
use Timer;
use sleep;
use Duration;
let mut timer = new;
// Simulate some work with a sleep
sleep;
// this will print elapsed time
timer.elapsed;
// Restart the timer with a new task name
timer.restart;
// Simulate more work
sleep;
// Measure elapsed time again
// consume timer and print elapsed time
timer.stop;
Logging Usage
use Timer;
use sleep;
use Duration;
let mut timer = new;
timer.log; // This will log the elapsed time using the log crate