Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nvzqz/divan
Fast and simple benchmarking for Rust projects
https://github.com/nvzqz/divan
benchmark fast rust simple
Last synced: 6 days ago
JSON representation
Fast and simple benchmarking for Rust projects
- Host: GitHub
- URL: https://github.com/nvzqz/divan
- Owner: nvzqz
- License: apache-2.0
- Created: 2023-06-30T05:01:57.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-05T01:15:52.000Z (about 2 months ago)
- Last Synced: 2025-01-13T05:00:08.961Z (13 days ago)
- Topics: benchmark, fast, rust, simple
- Language: Rust
- Homepage: https://nikolaivazquez.com/blog/divan/
- Size: 629 KB
- Stars: 1,011
- Watchers: 8
- Forks: 28
- Open Issues: 36
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE-APACHE
Awesome Lists containing this project
- awesome-rust - Divan
- awesome-rust - Divan - Simple yet powerful benchmarking library with allocation profiling (Development tools / Profiling)
- fucking-awesome-rust - Divan - Simple yet powerful benchmarking library with allocation profiling (Development tools / Profiling)
README
## Sponsor
If you or your company find Divan valuable, consider [sponsoring on
GitHub](https://github.com/sponsors/nvzqz) or [donating via
PayPal](https://paypal.me/nvzqz). Sponsorships help me progress on what's
possible with benchmarking in Rust.## Guide
A guide is being worked on. In the meantime, see:
- [Announcement post](https://nikolaivazquez.com/blog/divan/)
- ["Proving Performance" FOSDEM talk](https://youtu.be/P87C4jNakGs)## Getting Started
Divan `0.1.17` requires Rust `1.80.0` or later.
1. Add the following to your project's [`Cargo.toml`](https://doc.rust-lang.org/cargo/reference/manifest.html):
```toml
[dev-dependencies]
divan = "0.1.17"[[bench]]
name = "example"
harness = false
```2. Create a benchmarks file at `benches/example.rs`[^1] with your benchmarking code:
```rust
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)
}
}
```3. Run your benchmarks with [`cargo bench`](https://doc.rust-lang.org/cargo/commands/cargo-bench.html):
```txt
example fastest │ slowest │ median │ mean │ samples │ iters
╰─ fibonacci │ │ │ │ │
├─ 1 0.626 ns │ 1.735 ns │ 0.657 ns │ 0.672 ns │ 100 │ 819200
├─ 2 2.767 ns │ 3.154 ns │ 2.788 ns │ 2.851 ns │ 100 │ 204800
├─ 4 6.816 ns │ 7.671 ns │ 7.061 ns │ 7.167 ns │ 100 │ 102400
├─ 8 57.31 ns │ 62.51 ns │ 57.96 ns │ 58.55 ns │ 100 │ 12800
├─ 16 2.874 µs │ 3.812 µs │ 2.916 µs │ 3.006 µs │ 100 │ 200
╰─ 32 6.267 ms │ 6.954 ms │ 6.283 ms │ 6.344 ms │ 100 │ 100
```See [`#[divan::bench]`][bench_attr] for info on benchmark function registration.
## Examples
Practical example benchmarks can be found in the [`examples/benches`](https://github.com/nvzqz/divan/tree/main/examples/benches)
directory. These can be benchmarked locally by running:```sh
git clone https://github.com/nvzqz/divan.git
cd divancargo bench -q -p examples --all-features
```More thorough usage examples can be found in the [`#[divan::bench]` documentation][bench_attr_examples].
## License
Like the Rust project, this library may be used under either the
[MIT License](https://github.com/nvzqz/divan/blob/main/LICENSE-MIT) or
[Apache License (Version 2.0)](https://github.com/nvzqz/divan/blob/main/LICENSE-APACHE).[^1]: Within your crate directory, i.e. [`$CARGO_MANIFEST_DIR`](https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates)
[bench_attr]: https://docs.rs/divan/latest/divan/attr.bench.html
[bench_attr_examples]: https://docs.rs/divan/latest/divan/attr.bench.html#examples