divan icon indicating copy to clipboard operation
divan copied to clipboard

Better document running benchmarks outside of `cargo bench`

Open Swatinem opened this issue 2 years ago • 2 comments

Running the benchmarks using cargo bench works just fine as expected. It also prints the typical cargo Running benches/functions.rs (target/release/deps/functions-4227941eb3ee4115) line.

However running that target directly only lists the included benchmarks, it does not run them. This is a bit confusing if you want to run the benchmark directly in a profiler like samply.

Actually running the benchmarks needs the --bench flag:

https://github.com/nvzqz/divan/blob/0ff85855fd3aeacb2f24aa82ad90eb3efc93f060/src/divan.rs#L367-L376

However that flag is not documented at all in the command line flags:

https://github.com/nvzqz/divan/blob/0ff85855fd3aeacb2f24aa82ad90eb3efc93f060/src/cli.rs#L128-L129

It would be nice to actually document that flag, and maybe even provide an example how to run the benchmarks in a profiler like samply, which for me is as simple as running samply record target/release/deps/functions-4227941eb3ee4115 --bench

Swatinem avatar Nov 15 '23 09:11 Swatinem

FWIW this is pretty standard for all Rust benchmarking using a custom harness (e.g. Criterion has the same requirement).

vlovich avatar Nov 17 '23 06:11 vlovich

Here's my suggestion for running Divan outside of the benchmark harness:

fn main() {
    divan::Divan::from_args().run_benches();
}

nvzqz avatar Nov 20 '23 11:11 nvzqz