4

The Criterion benchmarking library for Rust is documented as generating plots describing the benchmark results:

Criterion.rs can generate a number of useful charts and graphs which you can check to get a better understanding of the behavior of the benchmark.

The plots and saved data are stored under target/criterion/$BENCHMARK_NAME/.

However, after running cargo bench and seeing Criterion's output on the terminal, I don't see a directory named target/criterion/. Where is the output now, or what do I have to do to activate it?

Kevin Reid
  • 37,492
  • 13
  • 80
  • 108

1 Answers1

3

This was a small bug (criterion issue #192): when Criterion is used in a Cargo workspace, it doesn't find the workspace's target directory, and ends up writing its results to <individual crate directory>/target/criterion instead.

The Cargo extension cargo-criterion was supposed to work around this but unfortunately for my particular case, currently didn't work on macOS (cargo-criterion issue #12).

Both issues has been fixed; since version 0.3.4 criterion writes its output to the correct directory, and cargo-criterion also works on macOS.

Kevin Reid
  • 37,492
  • 13
  • 80
  • 108
  • 1
    Is there anything I have to configure or pass to `cargo bench` to activate HTML reports / plot output? I'm using version 0.4.0 and I'm getting no HTML reports whatsoever using cargo workspace as well. To clarify, `target/criterion` contains some json files, but no html/png/svg files at all. – bluenote10 Mar 02 '23 at 21:19
  • 1
    I looks like it is now disabled by default and hidden behind a feature flag (`criterion = { version = "0.4", features = ["html_reports"] }`), which apparently now gets [reported frequently as an issue](https://github.com/bheisler/criterion.rs/issues/632), because the documentation and user guide still suggest otherwise. – bluenote10 Mar 02 '23 at 21:59