| Crates.io | codspeed-criterion-compat |
| lib.rs | codspeed-criterion-compat |
| version | 3.0.5 |
| created_at | 2023-01-11 11:25:17.349258+00 |
| updated_at | 2025-07-31 09:22:18.997529+00 |
| description | Criterion.rs compatibility layer for CodSpeed |
| homepage | https://codspeed.io |
| repository | https://github.com/CodSpeedHQ/codspeed-rust |
| max_upload_size | |
| id | 756344 |
| size | 88,249 |
cargo add --dev codspeed-criterion-compat --rename criterion
[!NOTE] This will install the
codspeed-criterion-compatcrate and rename it tocriterionin yourCargo.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-compatas is and change your imports to use this new crate name.
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)
iter_customwith_filter