| Crates.io | rustbench |
| lib.rs | rustbench |
| version | 0.1.2 |
| created_at | 2025-03-22 01:24:08.444134+00 |
| updated_at | 2025-03-23 17:48:23.225657+00 |
| description | A lightweight Rust procedural macro for benchmarking function execution time. |
| homepage | |
| repository | https://github.com/Harijayaraj-S/rustbench |
| max_upload_size | |
| id | 1601456 |
| size | 6,970 |
rustbench is a lightweight Rust procedural macro for benchmarking function execution time.
To use rustbench, add it to your Cargo.toml:
[dependencies]
rustbench = "0.1.1"
Then, add the macro as a procedural macro dependency:
[lib]
proc-macro = true
Simply annotate any function with #[benchmark] to measure its execution time.
use rustbench::benchmark;
#[benchmark]
fn example_sum() {
let _: u64 = (1..=1_000_000).sum();
}
#[benchmark(50)]
fn example_sum_iteration() {
let _: u64 = (1..=1_000_000).sum();
}
fn main() {
example_sum_iteration();
example_sum();
}
Function 'example_sum' executed in 7053000 ns
Iteration took: 11.716916ms
Iteration took: 10.26025ms
Iteration took: 9.13725ms
Iteration took: 8.560416ms
Iteration took: 7.905875ms
Function 'example_sum_iteration' executed 5 times. Avg time: 9516141 ns