tea-timer 0.1.2

A simple and efficient Rust library for measuring and reporting the duration of tasks
Documentation
  • Coverage
  • 52.94%
    9 out of 17 items documented9 out of 15 items with examples
  • Size
  • Source code size: 12.62 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 360.12 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 8s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Teamon9161/tea-timer
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Teamon9161

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 log crate

Installation

Add this to your Cargo.toml:

tea-timer = "0.1.0"

Usage

Macro Usage

let result = tea_timer::took! {
    // ...any code
};
// this will print elapsed time and get result of thecode block

Function Usage

use tea_timer::took;

let result = took(|| {
    // ...any code
}, "task");
// this will print elapsed time and get result of the function

Basic Usage

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();

Logging Usage

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