| Crates.io | clock_tower |
| lib.rs | clock_tower |
| version | 0.1.0 |
| created_at | 2025-12-03 13:53:43.101391+00 |
| updated_at | 2025-12-03 13:53:43.101391+00 |
| description | A thread-safe utility to measure the execution time of expressions and blocks, storing results in a global registry. |
| homepage | |
| repository | https://github.com/yourusername/clock_tower |
| max_upload_size | |
| id | 1964053 |
| size | 10,419 |
A simple, thread-safe Rust library for measuring the execution time of code blocks and expressions. Measurements are stored in a global registry for easy retrieval.
This project is licensed under the GPL-3.0 license. This ensures that any software using this library must also be open source.
Add this to your Cargo.toml:
[dependencies]
clock_tower = "0.1.0"
Use the measure! macro to wrap expressions or blocks. It returns the value of the expression while recording the time it took.
use clock_tower::{measure, time_registry};
use std::thread::sleep;
use std::time::Duration;
fn main() {
// Measure a simple expression
let result = measure!("simple_math", 21 + 21);
println!("Result: {}", result);
// Measure a block of code
let complex_result = measure!("heavy_task", {
sleep(Duration::from_millis(100));
let mut sum = 0;
for i in 0..1000 {
sum += i;
}
sum
});
println!("Complex Result: {}", complex_result);
}
You can access the recorded timings using the time_registry module.
use clock_tower::time_registry;
fn print_stats() {
// Get a specific measurement by name
if let Some((start, end, duration)) = time_registry::get("heavy_task") {
println!("Task 'heavy_task' took {:?}", duration);
}
// Iterate over all measurements
println!("All measurements:");
for (name, (_start, _end, duration)) in time_registry::all() {
println!("{} -> {:?}", name, duration);
}
// Clear registry if needed to start fresh
time_registry::clear();
}