Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better document running benchmarks outside of cargo bench #30

Open
Swatinem opened this issue Nov 15, 2023 · 2 comments
Open

Better document running benchmarks outside of cargo bench #30

Swatinem opened this issue Nov 15, 2023 · 2 comments

Comments

@Swatinem
Copy link

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:

divan/src/divan.rs

Lines 367 to 376 in 0ff8585

self.action = if matches.get_flag("list") {
Action::List
} else if matches.get_flag("test") || !matches.get_flag("bench") {
// Either of:
// `cargo bench -- --test`
// `cargo test --benches`
Action::Test
} else {
Action::Bench
};

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

divan/src/cli.rs

Lines 128 to 129 in 0ff8585

// ignored:
.args([ignored_flag("bench"), ignored_flag("nocapture"), ignored_flag("show-output")])

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
Copy link

vlovich commented Nov 17, 2023

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

@nvzqz
Copy link
Owner

nvzqz commented Nov 20, 2023

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants