lightweight benchmark framework for Rust
- Very small overhead
- Estimate memory usage
- Lightweight (does not depend on a heavy crate)
- Highly extensive and customizable
[dev-dependencies]
smbench = { git = "https://github.com/Kogia-sima/smbench" }
// benches/example.rs
use smbench::*;
#[inline]
fn fibonacci(n: u64) -> u64 {
let mut a = 0;
let mut b = 1;
match n {
0 => b,
_ => {
for _ in 0..n {
let c = a + b;
a = b;
b = c;
}
b
}
}
}
fn fibonacci_20(b: &mut Bencher) {
b.iter(|| fibonacci(black_box(20)));
}
fn heap_allocation(b: &mut Bencher) {
b.iter(|| Vec::<u32>::with_capacity(10));
}
// Define global allocator to trace memory allocation
smbench_trace_memory!();
smbench_group!(benchmark, fibonacci_20, heap_allocation);
smbench_main!(benchmark);
[[bench]]
name = "example"
harness = false
$ cargo bench -- --benchmem
Finished bench [optimized] target(s) in 0.02s
Running target/release/deps/example-a698a4f124b5c06c
OS Type: linux
CPU Architecture: x86_64
CPU Model Name: Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
Intel turbo boost technology: disabled
SMBench Version: 0.1.0
# benchmark (benches/example.rs)
Benchmark Time 95% CI Allocation
----------------------------------------------------------------------
fibonacci_20 9.8901 ns [9.8654 ns, 9.9147 ns] 0 B (0 allocs)
heap_allocation 34.138 ns [33.924 ns, 34.352 ns] 40 B (1 allocs)
cargo test
👤 Kogia sima
- Twitter: @Kogia_sima
- Github: @Kogia-sima
Contributions, issues and feature requests are welcome!
Feel free to check issues page.
Give a ⭐️ if this project helped you!
Copyright © 2020 Ryohei Machida.
This project is MIT licensed.
This README was generated with ❤️ by readme-md-generator