Macro criterion::criterion_main

source ·
macro_rules! criterion_main {
    ( $( $group:path ),+ $(,)* ) => { ... };
}
Available on non-crate feature codspeed only.
Expand description

Macro which expands to a benchmark harness.

Currently, using Criterion.rs requires disabling the benchmark harness generated automatically by rustc. This can be done like so:

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

In this case, my_bench must be a rust file inside the ‘benches’ directory, like so:

benches/my_bench.rs

Since we’ve disabled the default benchmark harness, we need to add our own:

use criterion::Criterion;
fn bench_method1(c: &mut Criterion) {
}

fn bench_method2(c: &mut Criterion) {
}

criterion_group!(benches, bench_method1, bench_method2);
criterion_main!(benches);

The criterion_main macro expands to a main function which runs all of the benchmarks in the given groups.