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 themain!
macroconfig
(optional): Acrate::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 thebenchmarks
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 groupteardown
(optional): A teardown function or any valid expression which is run after all benchmarks of this groupbenchmarks
(mandatory): A list of comma separated benchmark functions which must be annotated with#[library_benchmark]