bheisler / criterion.rs

Statistics-driven benchmarking library for Rust
Apache License 2.0
4.28k stars 290 forks source link

Save baseline does not work in 0.5 #780

Open aadrijnberg opened 2 months ago

aadrijnberg commented 2 months ago

When following the documentation to save a baseline with a name, it returns an error. See https://github.com/aadrijnberg/criterion-benchmark for the repo that tries to use it, but fails with an error:

$ cargo bench -- --save-baseline initial
Finished `bench` profile [optimized] target(s) in 0.10s
 Running unittests src/lib.rs (target/release/deps/criterion_benchmark-c2076c60856bf728)
error: Unrecognized option: 'save-baseline'
error: bench failed, to rerun pass `--lib`

Did I use the wrong command line parameters to store the baseline under a certain name, or is it not working in v0.5

d2weber commented 1 month ago

According to the FAQ, it should work with the explicit --bench my_benchmark argument:

cargo bench --bench my_benchmark -- --verbose

Note that my_benchmark here corresponds to the name of your benchmark in your Cargo.toml file.

Another option is to disable benchmarks for your lib or app crate. For example, for library crates, you could add this to your Cargo.toml file:

[lib]
bench = false
aadrijnberg commented 1 month ago

It is not that I cannot run the benchmarks, it is just that I cannot use the "save-baseline" feature. And I was wondering if my command line was wrong, or that this feature is not working as documented...

d2weber commented 1 month ago

It is not that I cannot run the benchmarks, it is just that I cannot use the "save-baseline" feature. And I was wondering if my command line was wrong, or that this feature is not working as documented...

I think my previous comment answers your question. The linked FAQ regards this specific case: 'cargo bench gives "Unrecognized Option" Errors for Valid Command-line Options'

Side note: If you run cargo bench -- --help the end of the message links to this exact same FAQ.

In your case, try:

cargo bench --bench my_benchmark -- --save-baseline initial

instead of

cargo bench -- --save-baseline initial
aad4 commented 2 weeks ago

Hah, thanks! That works.