2个版本
0.1.1 | 2020年9月24日 |
---|---|
0.1.0 | 2020年9月21日 |
#36 in #black-box
在bench-rs中使用
4KB
bench-rs
基准测试库。
- 稳定版Rust(无black_box)
- 美观的输出
- 异步支持
- 自定义异步运行时
- 内存使用
- 自定义格式化
- 直观的数值单位
- 支持自定义内存分配器
示例
$ cargo test --release --color=always -q --package bench-rs --test bench --no-fail-fast -- --test-threads=1 --nocapture
查看./tests/bench.rs
black_box
我不知道如何实现black_box。
请使用core::hint::black_box。 (不稳定)
如果您有更好的想法,欢迎提交pull request或打开issue
global_allocator
为了检测内存使用,bench-rs修改了global_allocator。这将使得无法使用其他分配器。如果您需要使用其他分配器
更改您的分配器:(如果您的分配器是std::alloc::System
)
use std::alloc::System;
use bench_rs::{TrackAllocator, new_allocator};
#[global_allocator]
pub static GLOBAL: TrackAllocator<System> = new_allocator!(System);
关闭默认特性
[dependencies]
bench-rs = { version = "*", default-features = false }
导入名为GLOBAL
的分配器
use bench_rs::bench;
use yourlib::GLOBAL;
#[bench]
fn ...
如果您的分配器名称不是GLOBAL
,请将其别名设置为GLOBAL
use yourlib::OtherAllocatoras GLOBAL
因为bencher-macro将在与bench函数相同级别查找GLOBAL.counter()
和GLOBAL.peak()
。
我是一个Rust初学者,如果代码有问题请纠正我。谢谢
欢迎贡献
依赖
~2MB
~42K SLoC