是否可以限制 Criterion 执行的迭代次数?
Is it possible to limit the number of iterations that Criterion performs?
我正在使用标准 (cargo bench
) 为板条箱开发一些基准。我想暂时限制迭代次数,直到我完成代码。
我知道测量值可能不准确,但这只是暂时的。这可能吗?
有可能。
看看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%。
我正在使用标准 (cargo bench
) 为板条箱开发一些基准。我想暂时限制迭代次数,直到我完成代码。
我知道测量值可能不准确,但这只是暂时的。这可能吗?
有可能。
看看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%。