nvzqz / divan

Fast and simple benchmarking for Rust projects
https://nikolaivazquez.com/blog/divan/
Apache License 2.0
849 stars 24 forks source link

Better document running benchmarks outside of `cargo bench` #30

Open Swatinem opened 7 months ago

Swatinem commented 7 months ago

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

vlovich commented 7 months ago

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

nvzqz commented 7 months ago

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

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