17 releases

new 0.1.15 Nov 1, 2024
0.1.14 Feb 17, 2024
0.1.11 Jan 21, 2024
0.1.8 Dec 19, 2023
0.0.0 Jun 30, 2023

#24 in #criterion

Download history 7446/week @ 2024-07-14 7039/week @ 2024-07-21 6999/week @ 2024-07-28 7375/week @ 2024-08-04 7637/week @ 2024-08-11 10538/week @ 2024-08-18 13592/week @ 2024-08-25 16208/week @ 2024-09-01 10481/week @ 2024-09-08 11324/week @ 2024-09-15 11359/week @ 2024-09-22 12488/week @ 2024-09-29 16196/week @ 2024-10-06 15437/week @ 2024-10-13 14021/week @ 2024-10-20 13786/week @ 2024-10-27

60,707 downloads per month
Used in 101 crates (via divan)

MIT/Apache

42KB
700 lines

Divan

docs.rs badge Downloads badge GitHub stars badge CI build status badge

Comfy benchmarking for Rust projects, brought to you by Nikolai Vazquez.

Sponsor

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.

Guide

A guide is being worked on. In the meantime, see:

Getting Started

  1. Add the following to your project's Cargo.toml:

    [dev-dependencies]
    divan = "0.1.15"
    
    [[bench]]
    name = "example"
    harness = false
    
  2. Create 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)
        }
    }
    
  3. Run your benchmarks with cargo bench:

    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] for info on benchmark function registration.

Examples

Practical 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-features

More thorough usage examples can be found in the #[divan::bench] documentation.

License

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

Dependencies

~250–700KB
~17K SLoC