iai_callgrind

Macro library_benchmark_group

source
macro_rules! library_benchmark_group {
    (
        $( config = $config:expr ; $(;)* )?
        $( compare_by_id = $compare:literal ; $(;)* )?
        $( setup = $setup:expr ; $(;)* )?
        $( teardown = $teardown:expr ; $(;)* )?
        benchmarks = $( $function:ident ),+
    ) => { ... };
    (
        name = $name:ident;
        $( config = $config:expr ; $(;)* )?
        $( compare_by_id = $compare:literal ; $(;)* )?
        $( setup = $setup:expr ; $(;)* )?
        $( teardown = $teardown:expr ; $(;)* )?
        benchmarks =
    ) => { ... };
    (
        name = $name:ident; $(;)*
        $( config = $config:expr ; $(;)* )?
        $( compare_by_id = $compare:literal ; $(;)* )?
        $( setup = $setup:expr ; $(;)* )?
        $( teardown = $teardown:expr ; $(;)* )?
        benchmarks = $( $function:ident ),+ $(,)*
    ) => { ... };
}
Available on crate feature default only.
Expand description

Macro used to define a group of library benchmarks

A small introductory example which shows the basic setup. This macro only accepts benchmarks annotated with #[library_benchmark] (crate::library_benchmark).

use iai_callgrind::{library_benchmark_group, library_benchmark};

#[library_benchmark]
fn bench_something() -> u64 {
    42
}

library_benchmark_group!(
    name = my_group;
    benchmarks = bench_something
);

iai_callgrind::main!(library_benchmark_groups = my_group);

To be benchmarked a library_benchmark_group has to be added to the main! macro by adding its name to the library_benchmark_groups argument of the main! macro. See there for further details about the crate::main macro.

The following top-level arguments are accepted in this order:

fn group_setup() {}
fn group_teardown() {}
library_benchmark_group!(
    name = my_group;
    config = LibraryBenchmarkConfig::default();
    compare_by_id = false;
    setup = group_setup();
    teardown = group_teardown();
    benchmarks = some_func
);
  • name (mandatory): A unique name used to identify the group for the main! macro
  • config (optional): A crate::LibraryBenchmarkConfig which is applied to all benchmarks within the same group.
  • compare_by_id (optional): The default is false. If true, all benches in the benchmark functions specified with the benchmarks argument, across any benchmark groups, are compared with each other as long as the ids (the part after the :: in #[bench::id(...)]) match.
  • setup (optional): A setup function or any valid expression which is run before all benchmarks of this group
  • teardown (optional): A teardown function or any valid expression which is run after all benchmarks of this group
  • benchmarks (mandatory): A list of comma separated benchmark functions which must be annotated with #[library_benchmark]