arbitime 0.1.1

Dead simple timing macros
Documentation
  • Coverage
  • 100%
    4 out of 4 items documented4 out of 4 items with examples
  • Size
  • Source code size: 15.88 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.2 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 14s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • rtificr/arbitime
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • rtificr

Arbitime

A simple Rust library for timing code execution with convenient macros.

Features

  • time! - Time code execution and return both duration and result
  • format_time! - Time code execution and format duration as a string
  • log_time! - Time code execution with automatic logging to stderr

Usage

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;

// Single operation with custom message
let (msg, result) = format_time!("Computing sum" => {
    (1..=1000).sum::<u32>()
});
println!("{}", msg); // "Computing sum - Execution time: 42.123µs"

// Simple timing without custom message
let (msg, result) = format_time! {
    expensive_operation()
};
println!("{}", msg); // "Execution time: 1.234ms"

Automatic logging with log_time!

use arbitime::log_time;

// Single operation with custom message
let result = log_time!("Computing sum" => {
    (1..=1000).sum::<u32>()
});
// Prints: "Computing sum - Execution time: 42.123µs"

// Simple timing without custom message
let result = log_time! {
    expensive_operation()
};
// 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.