17 stable releases

new 2.8.0-alpha.2 Feb 6, 2025
2.7.2 Sep 13, 2024
2.6.0 Apr 24, 2024
2.4.0 Feb 26, 2024
1.1.0 Mar 3, 2023

#43 in Profiling

Download history 20669/week @ 2024-10-21 22446/week @ 2024-10-28 16408/week @ 2024-11-04 16456/week @ 2024-11-11 16816/week @ 2024-11-18 15453/week @ 2024-11-25 21335/week @ 2024-12-02 15879/week @ 2024-12-09 18169/week @ 2024-12-16 16989/week @ 2024-12-23 18135/week @ 2024-12-30 37034/week @ 2025-01-06 35110/week @ 2025-01-13 37018/week @ 2025-01-20 31723/week @ 2025-01-27 39664/week @ 2025-02-03

147,364 downloads per month
Used in 61 crates (59 directly)

MIT/Apache

44KB
1K SLoC

codspeed-criterion-compat

CI Crates.io Discord CodSpeed Badge

Criterion.rs compatibility layer for CodSpeed

Installation

cargo add --dev codspeed-criterion-compat --rename criterion

[!NOTE] This will install the codspeed-criterion-compat crate and rename it to criterion in your Cargo.toml. This way, you can keep your existing imports and the compatibility layer will take care of the rest.

Using the compatibility layer won't change the behavior of your benchmark suite and Criterion.rs will still run it as usual.

If you prefer, you can also install codspeed-criterion-compat as is and change your imports to use this new crate name.

Usage

Let's start with the example from the Criterion.rs documentation, creating a benchmark suite for the Fibonacci function (in benches/my_benchmark.rs):

use criterion::{black_box, criterion_group, criterion_main, Criterion};

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

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

criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);

The last step in creating the Criterion benchmark is to add the new benchmark target in your Cargo.toml:

[[bench]]
name = "my_benchmark"
harness = false

And that's it! You can now run your benchmark suite with cargo-codspeed:

$ cargo codspeed build
    Finished release [optimized] target(s) in 0.12s
    Finished built 1 benchmark suite(s)

$ cargo codspeed run
   Collected 1 benchmark suite(s) to run
     Running my_benchmark
Using codspeed-criterion-compat v1.0.0 compatibility layer
NOTICE: codspeed is enabled, but no performance measurement will be made since it's running in an unknown environment.
Checked: benches/bencher_example.rs::fib_20 (group: benches)
        Done running bencher_example
    Finished running 1 benchmark suite(s)

Not supported:

  • iter_custom
  • with_filter

Dependencies

~6–21MB
~299K SLoC