15 个稳定版本

2.6.0 2024 年 4 月 24 日
2.4.0 2024 年 2 月 26 日
2.3.3 2023 年 11 月 20 日
2.1.0 2023 年 7 月 27 日
0.1.1 2022 年 12 月 16 日

#174性能分析

Download history 19/week @ 2024-04-14 510/week @ 2024-04-21 69/week @ 2024-04-28 9/week @ 2024-05-05 559/week @ 2024-05-12 574/week @ 2024-05-19 277/week @ 2024-05-26 127/week @ 2024-06-02 193/week @ 2024-06-09 105/week @ 2024-06-16 266/week @ 2024-06-23 100/week @ 2024-06-30 75/week @ 2024-07-07 88/week @ 2024-07-14 243/week @ 2024-07-21 142/week @ 2024-07-28

每月 554 次下载
用于 2 crate

MIT/Apache

21KB
442

codspeed-bencher-compat

CI Crates.io Discord CodSpeed Badge

CodSpeed 的 Bencher 兼容层

安装

cargo add --dev codspeed-bencher-compat

用法

让我们从 Bencher 文档 的示例开始,创建一个针对 2 个简单函数的基准测试套件(在 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);

创建 Bencher 基准测试的最后一个步骤是在您的 Cargo.toml 中添加新的基准测试目标

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

集成 CodSpeed

要允许 CodSpeed 与此套件交互,您只需将 bencher crate 的导入替换为 codspeed-bencher-compat crate

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

就是这样!您现在可以使用 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)

依赖关系

~0.6–11MB
~65K SLoC