我正在为使用标准(cargo bench)的机箱开发一些基准测试。我想暂时限制迭代次数,直到我完成代码。
我知道测量可能不精确,但这只是暂时的。这个是可能的吗?
发布于 2019-02-14 08:14:20
这是可能的。
看看Criterion Benchmark。在那里您可以找到与您相关的方法,特别是measurement_time。
深入挖掘,您可以找到如何使用它们here
fn bench(c: &mut Criterion) {
// Setup (construct data, allocate memory, etc)
c.bench(
"routines",
Benchmark::new("routine_1", |b| b.iter(|| routine_1()))
.with_function("routine_2", |b| b.iter(|| routine_2()))
.measurement_time(Duration::from_millis(1000))
);
}
criterion_group!(benches, bench);
criterion_main!(benches);其中measurement_time(Duration::from_millis(1000))是你要找的机器人。这有效地将我的特定函数的迭代次数减少了80%。
https://stackoverflow.com/questions/54672250
复制相似问题