| Crates.io | tea-timer |
| lib.rs | tea-timer |
| version | 0.1.2 |
| created_at | 2024-09-05 16:45:18.188395+00 |
| updated_at | 2024-09-09 02:30:24.822616+00 |
| description | A simple and efficient Rust library for measuring and reporting the duration of tasks |
| homepage | |
| repository | https://github.com/Teamon9161/tea-timer |
| max_upload_size | |
| id | 1364854 |
| size | 12,627 |
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.
log crateAdd this to your Cargo.toml:
tea-timer = "0.1.0"
let result = tea_timer::took! {
// ...any code
};
// this will print elapsed time and get result of thecode block
use tea_timer::took;
let result = took(|| {
// ...any code
}, "task");
// this will print elapsed time and get result of the function
use tea_timer::Timer;
use std::thread::sleep;
use std::time::Duration;
let mut timer = Timer::new("task");
// Simulate some work with a sleep
sleep(Duration::from_secs(2));
// this will print elapsed time
timer.elapsed();
// Restart the timer with a new task name
timer.restart("new_task");
// Simulate more work
sleep(Duration::from_millis(500));
// Measure elapsed time again
// consume timer and print elapsed time
timer.stop();
use tea_timer::Timer;
use std::thread::sleep;
use std::time::Duration;
let mut timer = Timer::new("task");
timer.log(); // This will log the elapsed time using the log crate