9 releases

0.2.5 Aug 27, 2018
0.2.4 Jul 9, 2018
0.2.3 Apr 15, 2018
0.2.2 Mar 25, 2018
0.1.1 Dec 13, 2017

#1 in Profiling

Download history 3046/week @ 2018-09-18 2618/week @ 2018-09-25 2893/week @ 2018-10-02 2054/week @ 2018-10-09 2947/week @ 2018-10-16 2606/week @ 2018-10-23 3690/week @ 2018-10-30 3767/week @ 2018-11-06 4381/week @ 2018-11-13 3747/week @ 2018-11-20 4272/week @ 2018-11-27 4804/week @ 2018-12-04 5181/week @ 2018-12-11

5,995 downloads per month
Used in 151 crates




Statistics-driven Microbenchmarking in Rust
Travis-CI | Appveyor | Crates.io | Coverage Status

Criterion.rs 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.
  • Benchmark external programs written in any language.


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

To start with Criterion.rs, 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/my_benchmark.rs 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 Criterion.rs 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.

Criterion.rs is currently in maintenance mode. New features are not currently being developed. If there's something you feel Criterion.rs is missing, feel free to raise an issue and submit a pull request.


First, thank you for contributing.

One great way to contribute to Criterion.rs 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 your issues or pull requests have no response after a few days, feel free to ping me (@bheisler)

For more details, see the CONTRIBUTING.md file

Compatibility Policy

Criterion.rs supports the last three stable minor releases of Rust. At time of writing, this means Rust 1.25 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 Criterion.rs may break support for such old versions, and this will not be considered a breaking change. If you require Criterion.rs to work on old versions of Rust, you will need to stick to a specific patch version of Criterion.rs.


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


Criterion.rs 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 Criterion.rs
  • cargo-benchcmp - Cargo subcommand to compare the output of two libtest or bencher benchmark runs


~101K SLoC