18 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
0.1.1 Dec 16, 2022

#199 in Profiling

Download history 2443/week @ 2024-10-21 2499/week @ 2024-10-28 2446/week @ 2024-11-04 2137/week @ 2024-11-11 1981/week @ 2024-11-18 1946/week @ 2024-11-25 2300/week @ 2024-12-02 1478/week @ 2024-12-09 1230/week @ 2024-12-16 781/week @ 2024-12-23 753/week @ 2024-12-30 1061/week @ 2025-01-06 994/week @ 2025-01-13 1201/week @ 2025-01-20 2097/week @ 2025-01-27 1885/week @ 2025-02-03

6,273 downloads per month
Used in 3 crates

MIT/Apache

25KB
528 lines

codspeed-bencher-compat

CI Crates.io Discord CodSpeed Badge

Bencher compatibility layer for CodSpeed

Installation

cargo add --dev codspeed-bencher-compat --rename bencher

[!NOTE] This will install the codspeed-bencher-compat crate and rename it to bencher 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 Bencher will still run it as usual.

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

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

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

~1–8.5MB
~73K SLoC