Macro iai_callgrind::main
source · macro_rules! main { ( callgrind_args = $( $args:literal ),* $(,)*; functions = $( $func_name:ident ),+ $(,)* ) => { ... }; ( $( $func_name:ident ),+ $(,)* ) => { ... }; }
Expand description
Macro which expands to a benchmark harness.
This macro has two forms:
ⓘ
main!(func1, func2)
or
ⓘ
main!(
callgrind_args = "--arg-with-flags=yes", "arg-without-flags=is_ok_too"
functions = func1, func2
)
Using Iai-callgrind requires disabling the benchmark harness generated automatically by rustc. This can be done like so:
[[bench]]
name = "my_bench"
harness = false
To be able to run any iai-callgrind benchmarks, you’ll also need the iai-callgrind-runner
installed with the binary somewhere in your $PATH for example with
cargo install iai-callgrind-runner
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 iai_callgrind::main;
// `#[inline(never)]` is important! Without it there won't be any metrics
#[inline(never)]
fn bench_method1() {
}
#[inline(never)]
fn bench_method2() {
}
main!(bench_method1, bench_method2);
The iai_callgrind::main
macro expands to a main
function which runs all of the benchmarks.