Hemera
Inevitable timing for Rust functions—measure execution with divine precision.
Hemera is a lightweight, zero-overhead procedural macro for measuring function execution time in Rust. Named after the Greek primordial goddess of the day, Hemera brings clarity and insight to your code's performance characteristics.
Features
- Zero-cost abstraction: Minimal runtime overhead (~36 nanoseconds)
- Sync & Async support: Works seamlessly with both synchronous and asynchronous functions
- Flexible logging: Choose between
println!andeprintln! - Conditional logging: Set thresholds to only log slow executions
- Custom labels: Override function names in logs
- Tracing integration: Optional support for the
tracingecosystem - Generics support: Works with generic functions and lifetimes
- Easy to use: Just add
#[measure_time]to any function
Installation
Add Hemera to your Cargo.toml:
Or manually:
[]
= "0.1"
For tracing integration:
[]
= { = "0.1", = ["tracing"] }
Usage
Basic Example
use measure_time;
Async Functions
use measure_time;
async
async
Custom Name
// Output: [TIMING] Function 'DatabaseQuery' executed in 45.678ms
Debug Level Logging
Use eprintln! instead of println!:
Threshold-based Logging
Only log if execution time exceeds a threshold:
Supported units: s (seconds), ms (milliseconds), us (microseconds), ns (nanoseconds)
Combine All Options
async
Generics Support
Hemera works seamlessly with generic functions:
async
Configuration Options
| Attribute | Type | Default | Description |
|---|---|---|---|
name |
String |
Function name | Custom label for the function in logs |
level |
"info" | "debug" |
"info" |
Log level (info uses println!, debug uses eprintln!) |
threshold |
String |
None | Minimum duration to log (e.g., "10ms", "1s") |
Feature Flags
| Feature | Description |
|---|---|
tracing |
Enable integration with the tracing crate |
Using with Tracing
[]
= { = "0.1", = ["tracing"] }
= "0.1"
When the tracing feature is enabled, Hemera automatically creates tracing spans around your functions.
Roadmap
| Feature | Status |
|---|---|
| Sync functions | Complete |
| Async functions | Complete |
| Threshold filtering | Complete |
| Custom naming | Complete |
| Debug/Info levels | Complete |
| Tracing integration | Complete |
| Block-level measurement | Planned |
| Statistical aggregation | Planned |
| Custom output formatters | Planned |
Examples
Check out the examples directory for more usage examples:
basic.rs- Synchronous function examplesasync_example.rs- Async function examples
Run examples with:
Benchmarks
Run benchmarks to measure the macro's overhead:
Benchmark results are saved as HTML reports in target/criterion/. Open target/criterion/report/index.html in your browser to view detailed performance analysis with charts and statistics.
Testing
Run the test suite:
# Run all tests
# Run tests without features
# Run with tracing feature
Author: Kunal Singh Dadhwal