【问题标题】:Is it possible to limit the number of iterations that Criterion performs?是否可以限制 Criterion 执行的迭代次数?
【发布时间】:2019-02-13 14:13:22
【问题描述】:

我正在使用标准 (cargo bench) 为板条箱开发一些基准。我想暂时限制迭代次数,直到我完成代码。

我知道测量可能不精确,但这只是暂时的。这可能吗?

【问题讨论】:

    标签: rust rust-criterion


    【解决方案1】:

    有可能。

    查看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%。

    【讨论】:

      猜你喜欢
      • 2017-09-16
      • 2015-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-01
      • 2015-05-23
      相关资源
      最近更新 更多