Configuration
Library benchmarks can be configured with the LibraryBenchmarkConfig
and
with Command-line arguments and Environment
variables.
The LibraryBenchmarkConfig
can be specified at different levels and sets the
configuration values for the same and lower levels. The values of the
LibraryBenchmarkConfig
at higher levels can be overridden at a lower level.
Note that some values are additive rather than substitutive. Please see the docs
of the respective functions in LibraryBenchmarkConfig
for more details.
The different levels where a LibraryBenchmarkConfig
can be specified.
- At top-level with the
main!
macro
extern crate iai_callgrind; use iai_callgrind::{library_benchmark, library_benchmark_group}; use iai_callgrind::{main, LibraryBenchmarkConfig}; #[library_benchmark] fn bench() {} library_benchmark_group!(name = my_group; benchmarks = bench); fn main() { main!( config = LibraryBenchmarkConfig::default(); library_benchmark_groups = my_group ); }
- At group-level in the
library_benchmark_group!
macro
extern crate iai_callgrind; use iai_callgrind::library_benchmark; use iai_callgrind::{main, LibraryBenchmarkConfig, library_benchmark_group}; #[library_benchmark] fn bench() {} library_benchmark_group!( name = my_group; config = LibraryBenchmarkConfig::default(); benchmarks = bench ); fn main() { main!(library_benchmark_groups = my_group); }
- At
#[library_benchmark]
level
extern crate iai_callgrind; mod my_lib { pub fn bubble_sort(_: Vec<i32>) -> Vec<i32> { vec![] } } use iai_callgrind::{ main, LibraryBenchmarkConfig, library_benchmark_group, library_benchmark }; use std::hint::black_box; #[library_benchmark(config = LibraryBenchmarkConfig::default())] fn bench() { /* ... */ } library_benchmark_group!( name = my_group; config = LibraryBenchmarkConfig::default(); benchmarks = bench ); fn main() { main!(library_benchmark_groups = my_group); }
- and at
#[bench]
,#[benches]
level
extern crate iai_callgrind; mod my_lib { pub fn bubble_sort(_: Vec<i32>) -> Vec<i32> { vec![] } } use iai_callgrind::{ main, LibraryBenchmarkConfig, library_benchmark_group, library_benchmark }; use std::hint::black_box; #[library_benchmark] #[bench::some_id(args = (1, 2), config = LibraryBenchmarkConfig::default())] #[benches::multiple( args = [(3, 4), (5, 6)], config = LibraryBenchmarkConfig::default() )] fn bench(a: u8, b: u8) { /* ... */ _ = (a, b); } library_benchmark_group!( name = my_group; config = LibraryBenchmarkConfig::default(); benchmarks = bench ); fn main() { main!(library_benchmark_groups = my_group); }