2 releases
new 0.1.1 | Mar 23, 2025 |
---|---|
0.1.0 | Mar 22, 2025 |
#1577 in Rust patterns
38 downloads per month
6KB
75 lines
Rustbench
rustbench
is a lightweight Rust procedural macro for benchmarking function execution time.
Installation
To use rustbench
, add it to your Cargo.toml
:
[dependencies]
rustbench = "0.1.0"
Then, add the macro as a procedural macro dependency:
[lib]
proc-macro = true
Usage
Simply annotate any function with #[benchmark]
to measure its execution time.
use rustbench::benchmark;
#[benchmark]
fn sum() {
let sum: u64 = (1..=1_000_000).sum();
println!("Sum: {}", sum);
}
fn main() {
sum();
}
Output
When sum
runs, it prints the execution time:
Function sum executed in 12.3ms
Features (Planned)
- Custom Iterations: Run the function multiple times for better measurement.
- Comparison Mode: Compare execution time of two functions.
- Output Formats: JSON, CSV, or plain text.
- Memory Profiling: Measure memory usage during execution.
- Integration with Logging: Store benchmark results in logs.
Dependencies
~190–620KB
~15K SLoC