Fast and simple benchmarking for Rust projects
If you or your company find Divan valuable, consider sponsoring on GitHub or donating via PayPal. Sponsorships help me progress on what's possible with benchmarking in Rust.
A guide is being worked on. In the meantime, see:
Divan 0.1.21 requires Rust 1.80.0 or later.
Add the following to your project's Cargo.toml:
[dev-dependencies]
divan = "0.1.21"
[[bench]]
name = "example"
harness = falseCreate a benchmarks file at benches/example.rs[^1] with your benchmarking code:
fn main() {
// Run registered benchmarks.
divan::main();
}
// Register a `fibonacci` function and benchmark it over multiple cases.
#[divan::bench(args = [1, 2, 4, 8, 16, 32])]
fn fibonacci(n: u64) -> u64 {
if n <= 1 {
1
} else {
fibonacci(n - 2) + fibonacci(n - 1)
}
}Run your benchmarks with cargo bench:
…See #[divan::bench] for info on benchmark function registration.
If you want to run each benchmarked function only once (to check that they don't panic without measuring their performance), you can run the benchmark runner crate with the --test parameter. You can do so by running either
cargo bench -- --testor
cargo test --benchesPractical example benchmarks can be found in the examples/benches
directory. These can be benchmarked locally by running:
git clone https://github.com/nvzqz/divan.git
cd divan
cargo bench -q -p examples --all-featuresMore thorough usage examples can be found in the #[divan::bench] documentation.
Like the Rust project, this library may be used under either the MIT License or Apache License (Version 2.0).
[^1]: Within your crate directory, i.e. $CARGO_MANIFEST_DIR
No open issues yet, or sync has not completed.