Benchmarking

Running benchmarks in Rust is done via cargo bench, a specific command for cargo which executes all the methods annotated with the #[bench] attribute. This attribute is currently unstable and available only for the nightly channel.

Java users can make use of the Java Microbenchmark Harness (JMH) tool to write microbenchmarks for their Java code. The equivalent of JMH for Rust is a crate named Criterion.

As per its documentation, Criterion collects and stores statistical information from run to run and can automatically detect performance regressions as well as measuring optimizations.

With Criterion, it is possible to use the #[bench] attribute without moving to the nightly channel.

It is possible to integrate benchmark results with the GitHub Action for Continuous Benchmarking. Criterion, in fact, supports multiple output formats, amongst which there is also the bencher format, mimicking the nightly libtest benchmarks and compatible with the mentioned action.