10 stable releases

2.3.3 Nov 20, 2023
2.3.2 Nov 14, 2023
2.3.1 Oct 23, 2023
2.2.0 Sep 5, 2023
0.1.1 Dec 16, 2022

#64 in Profiling

Download history 7/week @ 2023-08-14 1/week @ 2023-08-21 15/week @ 2023-08-28 38/week @ 2023-09-04 2/week @ 2023-09-11 4/week @ 2023-09-18 2/week @ 2023-10-02 1/week @ 2023-10-09 25/week @ 2023-10-16 29/week @ 2023-10-23 39/week @ 2023-10-30 15/week @ 2023-11-06 33/week @ 2023-11-13 78/week @ 2023-11-20 70/week @ 2023-11-27

198 downloads per month
Used in jiter

MIT/Apache

20KB
428 lines

codspeed-bencher-compat

CI Crates.io Discord CodSpeed Badge

Bencher compatibility layer for CodSpeed

Installation

cargo add --dev codspeed-bencher-compat

Usage

Let's start with the example from the Bencher documentation, creating a benchmark suite for 2 simple functions (in benches/example.rs):

use bencher::{benchmark_group, benchmark_main, Bencher};

fn a(bench: &mut Bencher) {
    bench.iter(|| {
        (0..1000).fold(0, |x, y| x + y)
    })
}

fn b(bench: &mut Bencher) {
    const N: usize = 1024;
    bench.iter(|| {
        vec![0u8; N]
    });

    bench.bytes = N as u64;
}

benchmark_group!(benches, a, b);
benchmark_main!(benches);

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

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

Plugging CodSpeed

To allow CodSpeed to interact with this suite as well, you simply need to replace the imports from the bencher crate to the codspeed-bencher-compat crate:

- use bencher::{benchmark_group, benchmark_main, Bencher};
+ use codspeed_bencher_compat::{benchmark_group, benchmark_main, Bencher};

And that's it! You can now run your benchmark suite with 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 example
Using codspeed-bencher-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/example.rs::a (group: benches)
Checked: benches/example.rs::b (group: benches)
        Done running bencher_example
    Finished running 1 benchmark suite(s)

Dependencies

~0.5–9.5MB
~97K SLoC