Skip to content
Statistics-driven benchmarking library for Rust
Branch: master
Clone or download
Latest commit cc4d5e8 Mar 8, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
bencher_compat Update version numbers again, to fix incompatibility between criterio… Jan 19, 2019
benches Add NumBatches/NumIterations to BatchSize. Feb 9, 2019
book Fix new HTML report in the user guide. Feb 9, 2019
ci Fix new HTML report in the user guide. Feb 9, 2019
plot Add notice that criterion-plot is looking for a maintainer. Jan 20, 2019
src text_coloring: Disable Unix configuration macro Mar 5, 2019
tests Add NumBatches/NumIterations to BatchSize. Feb 9, 2019
.gitignore criterion no longer depends on criterion_macros Feb 23, 2016
.travis.yml Bump minimum supported Rust version to 1.29 Jan 19, 2019 Update all links to point to the new repository URL. Dec 8, 2018
appveyor.yml Fix Appveyor builds. Jan 21, 2018

Statistics-driven Microbenchmarking in Rust
Travis-CI | Appveyor | helps you write fast code by detecting and measuring performance improvements or regressions, even small ones, quickly and accurately. You can optimize with confidence, knowing how each change affects the performance of your code.

Table of Contents


  • Statistics: Statistical analysis detects if, and by how much, performance has changed since the last benchmark run
  • Charts: Uses gnuplot to generate detailed graphs of benchmark results.
  • Stable-compatible: Benchmark your code without installing nightly Rust.


In order to generate plots, you must have gnuplot installed. See the gnuplot website for installation instructions. also currently requires Rust 1.28 or later (see Compatibility Policy for more details).

To start with, add the following to your Cargo.toml file:

criterion = "0.2"

name = "my_benchmark"
harness = false

Next, define a benchmark by creating a file at $PROJECT/benches/ with the following contents.

extern crate criterion;

use criterion::Criterion;

fn fibonacci(n: u64) -> u64 {
    match n {
        0 => 1,
        1 => 1,
        n => fibonacci(n-1) + fibonacci(n-2),

fn criterion_benchmark(c: &mut Criterion) {
    c.bench_function("fib 20", |b| b.iter(|| fibonacci(20)));

criterion_group!(benches, criterion_benchmark);

Finally, run this benchmark with cargo bench. You should see output similar to the following:

     Running target/release/deps/example-423eedc43b2b3a93
fib 20                  time:   [26.029 us 26.251 us 26.505 us]
Found 11 outliers among 99 measurements (11.11%)
  6 (6.06%) high mild
  5 (5.05%) high severe

See the Getting Started guide for more details.


The primary goal of is to provide a powerful and statistically rigorous tool for measuring the performance of code, preventing performance regressions and accurately measuring optimizations. Additionally, it should be as programmer-friendly as possible and make it easy to create reliable, useful benchmarks, even for programmers without an advanced background in statistics.


First, thank you for contributing.

One great way to contribute to is to use it for your own benchmarking needs and report your experiences, file and comment on issues, etc.

Code or documentation improvements in the form of pull requests are also welcome. If you're not sure what to work on, try checking the Beginner label

If your issues or pull requests have no response after a few days, feel free to ping me (@bheisler)

For more details, see the file

Compatibility Policy supports the last three stable minor releases of Rust. At time of writing, this means Rust 1.29 or later. Older versions may work, but are not tested or guaranteed.

Currently, the oldest version of Rust believed to work is 1.23. Future versions of may break support for such old versions, and this will not be considered a breaking change. If you require to work on old versions of Rust, you will need to stick to a specific patch version of

Maintenance was originally created by Jorge Aparicio (@japaric) and is currently being maintained by Brook Heisler (@bheisler).

License is dual licensed under the Apache 2.0 license and the MIT license.

Related Projects

  • bencher - A port of the libtest benchmark runner to stable Rust
  • criterion - The Haskell microbenchmarking library that inspired
  • cargo-benchcmp - Cargo subcommand to compare the output of two libtest or bencher benchmark runs
You can’t perform that action at this time.