pub struct LibraryBenchmarkConfig(/* private fields */);
default
only.Expand description
The main configuration of a library benchmark.
See LibraryBenchmarkConfig::callgrind_args
for more details.
§Examples
use iai_callgrind::{LibraryBenchmarkConfig, main};
main!(
config = LibraryBenchmarkConfig::default()
.callgrind_args(["toggle-collect=something"]);
library_benchmark_groups = some_group
);
Implementations§
source§impl LibraryBenchmarkConfig
impl LibraryBenchmarkConfig
sourcepub fn with_raw_callgrind_args<I, T>(args: T) -> Self
👎Deprecated: Please use with_callgrind_args
pub fn with_raw_callgrind_args<I, T>(args: T) -> Self
Create a new LibraryBenchmarkConfig
with initial callgrind arguments
See also LibraryBenchmarkConfig::callgrind_args
.
§Examples
use iai_callgrind::{LibraryBenchmarkConfig, main};
main!(
config =
LibraryBenchmarkConfig::with_callgrind_args(["toggle-collect=something"]);
library_benchmark_groups = some_group
);
sourcepub fn raw_callgrind_args<I, T>(&mut self, args: T) -> &mut Self
👎Deprecated: Please use callgrind_args
pub fn raw_callgrind_args<I, T>(&mut self, args: T) -> &mut Self
Add callgrind arguments to this LibraryBenchmarkConfig
The arguments don’t need to start with a flag: --toggle-collect=some
or
toggle-collect=some
are both understood.
Not all callgrind arguments are understood by iai-callgrind
or cause problems in
iai-callgrind
if they would be applied. iai-callgrind
will issue a warning in such
cases. Most of the defaults can be overwritten. The default settings are:
--I1=32768,8,64
--D1=32768,8,64
--LL=8388608,16,64
--cache-sim=yes
--toggle-collect=...
(see alsoLibraryBenchmarkConfig::entry_point
)--collect-atstart=no
--compress-pos=no
--compress-strings=no
Note that toggle-collect
is an array and the default EntryPoint
for library benchmarks
is the benchmark function.
See also Callgrind Command-line Options
§Examples
use iai_callgrind::{LibraryBenchmarkConfig, main};
main!(
config = LibraryBenchmarkConfig::default()
.callgrind_args(["toggle-collect=something"]);
library_benchmark_groups = some_group
);
sourcepub fn raw_callgrind_args_iter<I, T>(&mut self, args: T) -> &mut Self
👎Deprecated: Please use callgrind_args
pub fn raw_callgrind_args_iter<I, T>(&mut self, args: T) -> &mut Self
Add elements of an iterator over callgrind arguments to this LibraryBenchmarkConfig
See also LibraryBenchmarkConfig::callgrind_args
§Examples
use iai_callgrind::{LibraryBenchmarkConfig, main};
main!(
config = LibraryBenchmarkConfig::default()
.raw_callgrind_args_iter(["toggle-collect=something"].iter());
library_benchmark_groups = some_group
);
sourcepub fn with_callgrind_args<I, T>(args: T) -> Self
pub fn with_callgrind_args<I, T>(args: T) -> Self
Create a new LibraryBenchmarkConfig
with callgrind arguments
See also LibraryBenchmarkConfig::callgrind_args
.
§Examples
use iai_callgrind::{LibraryBenchmarkConfig, main};
main!(
config =
LibraryBenchmarkConfig::with_callgrind_args(["toggle-collect=something"]);
library_benchmark_groups = some_group
);
sourcepub fn callgrind_args<I, T>(&mut self, args: T) -> &mut Self
pub fn callgrind_args<I, T>(&mut self, args: T) -> &mut Self
Add callgrind arguments to this LibraryBenchmarkConfig
The arguments don’t need to start with a flag: --toggle-collect=some
or
toggle-collect=some
are both understood.
Not all callgrind arguments are understood by iai-callgrind
or cause problems in
iai-callgrind
if they would be applied. iai-callgrind
will issue a warning in such
cases. Most of the defaults can be overwritten. The default settings are:
--I1=32768,8,64
--D1=32768,8,64
--LL=8388608,16,64
--cache-sim=yes
--toggle-collect=...
(see alsoLibraryBenchmarkConfig::entry_point
)--collect-atstart=no
--compress-pos=no
--compress-strings=no
Note that toggle-collect
is an array and the default EntryPoint
for library benchmarks
is the benchmark function.
See also Callgrind Command-line Options
§Examples
use iai_callgrind::{LibraryBenchmarkConfig, main};
main!(
config = LibraryBenchmarkConfig::default()
.callgrind_args(["toggle-collect=something"]);
library_benchmark_groups = some_group
);
sourcepub fn valgrind_args<I, T>(&mut self, args: T) -> &mut Self
pub fn valgrind_args<I, T>(&mut self, args: T) -> &mut Self
Pass valgrind arguments to all tools
Only core valgrind arguments are allowed.
These arguments can be overwritten by tool specific arguments for example with
LibraryBenchmarkConfig::callgrind_args
or crate::Tool::args
.
§Examples
Specify --trace-children=no
for all configured tools (including callgrind):
use iai_callgrind::{main, LibraryBenchmarkConfig, Tool, ValgrindTool};
main!(
config = LibraryBenchmarkConfig::default()
.valgrind_args(["--trace-children=no"])
.tool(Tool::new(ValgrindTool::DHAT));
library_benchmark_groups = my_group
);
Overwrite the valgrind argument --num-callers=25
for DHAT
with --num-callers=30
:
use iai_callgrind::{main, LibraryBenchmarkConfig, Tool, ValgrindTool};
main!(
config = LibraryBenchmarkConfig::default()
.valgrind_args(["--num-callers=25"])
.tool(Tool::new(ValgrindTool::DHAT)
.args(["--num-callers=30"])
);
library_benchmark_groups = my_group
);
sourcepub fn env_clear(&mut self, value: bool) -> &mut Self
pub fn env_clear(&mut self, value: bool) -> &mut Self
Clear the environment variables before running a benchmark (Default: true)
§Examples
use iai_callgrind::{LibraryBenchmarkConfig, main};
main!(
config = LibraryBenchmarkConfig::default().env_clear(false);
library_benchmark_groups = some_group
);
sourcepub fn env<K, V>(&mut self, key: K, value: V) -> &mut Self
pub fn env<K, V>(&mut self, key: K, value: V) -> &mut Self
Add an environment variables which will be available in library benchmarks
These environment variables are available independently of the setting of
LibraryBenchmarkConfig::env_clear
.
§Examples
An example for a custom environment variable, available in all benchmarks:
use iai_callgrind::{LibraryBenchmarkConfig, main};
main!(
config = LibraryBenchmarkConfig::default().env("FOO", "BAR");
library_benchmark_groups = some_group
);
sourcepub fn envs<K, V, T>(&mut self, envs: T) -> &mut Self
pub fn envs<K, V, T>(&mut self, envs: T) -> &mut Self
Add multiple environment variables which will be available in library benchmarks
See also LibraryBenchmarkConfig::env
for more details.
§Examples
use iai_callgrind::{LibraryBenchmarkConfig, main};
main!(
config =
LibraryBenchmarkConfig::default().envs([("MY_CUSTOM_VAR", "SOME_VALUE"), ("FOO", "BAR")]);
library_benchmark_groups = some_group
);
sourcepub fn pass_through_env<K>(&mut self, key: K) -> &mut Self
pub fn pass_through_env<K>(&mut self, key: K) -> &mut Self
Specify a pass-through environment variable
Usually, the environment variables before running a library benchmark are cleared but specifying pass-through variables makes this environment variable available to the benchmark as it actually appeared in the root environment.
Pass-through environment variables are ignored if they don’t exist in the root environment.
§Examples
Here, we chose to pass through the original value of the HOME
variable:
use iai_callgrind::{LibraryBenchmarkConfig, main};
main!(
config = LibraryBenchmarkConfig::default().pass_through_env("HOME");
library_benchmark_groups = some_group
);
sourcepub fn pass_through_envs<K, T>(&mut self, envs: T) -> &mut Self
pub fn pass_through_envs<K, T>(&mut self, envs: T) -> &mut Self
Specify multiple pass-through environment variables
See also LibraryBenchmarkConfig::pass_through_env
.
§Examples
use iai_callgrind::{LibraryBenchmarkConfig, main};
main!(
config = LibraryBenchmarkConfig::default().pass_through_envs(["HOME", "USER"]);
library_benchmark_groups = some_group
);
sourcepub fn flamegraph<T>(&mut self, config: T) -> &mut Selfwhere
T: Into<InternalFlamegraphConfig>,
pub fn flamegraph<T>(&mut self, config: T) -> &mut Selfwhere
T: Into<InternalFlamegraphConfig>,
Option to produce flamegraphs from callgrind output using the crate::FlamegraphConfig
§Examples
use iai_callgrind::{LibraryBenchmarkConfig, main, FlamegraphConfig};
main!(
config = LibraryBenchmarkConfig::default().flamegraph(FlamegraphConfig::default());
library_benchmark_groups = some_group
);
sourcepub fn regression<T>(&mut self, config: T) -> &mut Selfwhere
T: Into<InternalRegressionConfig>,
pub fn regression<T>(&mut self, config: T) -> &mut Selfwhere
T: Into<InternalRegressionConfig>,
Enable performance regression checks with a crate::RegressionConfig
§Examples
use iai_callgrind::{LibraryBenchmarkConfig, main, RegressionConfig};
main!(
config = LibraryBenchmarkConfig::default().regression(RegressionConfig::default());
library_benchmark_groups = some_group
);
sourcepub fn tool<T>(&mut self, tool: T) -> &mut Selfwhere
T: Into<InternalTool>,
pub fn tool<T>(&mut self, tool: T) -> &mut Selfwhere
T: Into<InternalTool>,
Add a configuration to run a valgrind crate::Tool
in addition to callgrind
§Examples
use iai_callgrind::{LibraryBenchmarkConfig, main, Tool, ValgrindTool};
main!(
config = LibraryBenchmarkConfig::default()
.tool(Tool::new(ValgrindTool::DHAT));
library_benchmark_groups = some_group
);
sourcepub fn tools<I, T>(&mut self, tools: T) -> &mut Self
pub fn tools<I, T>(&mut self, tools: T) -> &mut Self
Add multiple configurations to run valgrind crate::Tool
s in addition to callgrind
§Examples
use iai_callgrind::{LibraryBenchmarkConfig, main, Tool, ValgrindTool};
main!(
config = LibraryBenchmarkConfig::default()
.tools(
[
Tool::new(ValgrindTool::DHAT),
Tool::new(ValgrindTool::Massif)
]
);
library_benchmark_groups = some_group
);
sourcepub fn tool_override<T>(&mut self, tool: T) -> &mut Selfwhere
T: Into<InternalTool>,
pub fn tool_override<T>(&mut self, tool: T) -> &mut Selfwhere
T: Into<InternalTool>,
Override previously defined configurations of valgrind crate::Tool
s
Usually, if specifying crate::Tool
configurations with LibraryBenchmarkConfig::tool
these tools are appended to the configuration of a LibraryBenchmarkConfig
of
higher-levels. Specifying a crate::Tool
with this method overrides previously defined
configurations.
Note that crate::Tool
s specified with LibraryBenchmarkConfig::tool
will be ignored,
if in the very same LibraryBenchmarkConfig
, crate::Tool
s are specified by this method
(or LibraryBenchmarkConfig::tools_override
).
§Examples
The following will run DHAT
and Massif
(and the default callgrind) for all benchmarks in
main!
besides for some_func
which will just run Memcheck
(and callgrind).
use iai_callgrind::{
main, library_benchmark, library_benchmark_group, LibraryBenchmarkConfig, Tool, ValgrindTool
};
#[library_benchmark(config = LibraryBenchmarkConfig::default()
.tool_override(
Tool::new(ValgrindTool::Memcheck)
)
)]
fn some_func() {}
library_benchmark_group!(
name = some_group;
benchmarks = some_func
);
main!(
config = LibraryBenchmarkConfig::default()
.tools(
[
Tool::new(ValgrindTool::DHAT),
Tool::new(ValgrindTool::Massif)
]
);
library_benchmark_groups = some_group
);
sourcepub fn tools_override<I, T>(&mut self, tools: T) -> &mut Self
pub fn tools_override<I, T>(&mut self, tools: T) -> &mut Self
Override previously defined configurations of valgrind crate::Tool
s
See also LibraryBenchmarkConfig::tool_override
.
§Examples
The following will run DHAT
(and the default callgrind) for all benchmarks in
main!
besides for some_func
which will run Massif
and Memcheck
(and callgrind).
use iai_callgrind::{
main, library_benchmark, library_benchmark_group, LibraryBenchmarkConfig, Tool, ValgrindTool
};
#[library_benchmark(config = LibraryBenchmarkConfig::default()
.tools_override([
Tool::new(ValgrindTool::Massif),
Tool::new(ValgrindTool::Memcheck)
])
)]
fn some_func() {}
library_benchmark_group!(
name = some_group;
benchmarks = some_func
);
main!(
config = LibraryBenchmarkConfig::default()
.tool(
Tool::new(ValgrindTool::DHAT),
);
library_benchmark_groups = some_group
);
sourcepub fn entry_point<T>(&mut self, entry_point: T) -> &mut Selfwhere
T: Into<EntryPoint>,
pub fn entry_point<T>(&mut self, entry_point: T) -> &mut Selfwhere
T: Into<EntryPoint>,
Set or unset the entry point for a benchmark
Iai-Callgrind sets the --toggle-collect
argument of callgrind to the benchmark function
which we call EntryPoint::Default
. Specifying a --toggle-collect
argument, sets
automatically --collect-at-start=no
. This ensures that only the metrics from the benchmark
itself are collected and not the setup
or teardown
or anything before/after the
benchmark function.
However, there are cases when the default toggle is not enough EntryPoint::Custom
or in
the way EntryPoint::None
.
Setting EntryPoint::Custom
is convenience for disabling the entry point with
EntryPoint::None
and setting --toggle-collect=CUSTOM_ENTRY_POINT
in
LibraryBenchmarkConfig::callgrind_args
. EntryPoint::Custom
can be useful if you
want to benchmark a private function and only need the function in the benchmark function as
access point. EntryPoint::Custom
accepts glob patterns the same way as
--toggle-collect
does.
§Examples
If you’re using callgrind client requests either in the benchmark function itself or in your
library, then using EntryPoint::None
is presumably be required. Consider the following
example (DEFAULT_ENTRY_POINT
marks the default entry point):
use iai_callgrind::{
main, LibraryBenchmarkConfig,library_benchmark, library_benchmark_group
};
use std::hint::black_box;
fn to_be_benchmarked() -> u64 {
println!("Some info output");
iai_callgrind::client_requests::callgrind::start_instrumentation();
let result = {
// some heavy calculations
};
iai_callgrind::client_requests::callgrind::stop_instrumentation();
result
}
#[library_benchmark]
fn some_bench() -> u64 { // <-- DEFAULT ENTRY POINT
black_box(to_be_benchmarked())
}
library_benchmark_group!(name = some_group; benchmarks = some_bench);
main!(library_benchmark_groups = some_group);
In the example above EntryPoint::Default
is active, so the counting of events starts
when the some_bench
function is entered. In to_be_benchmarked
, the client request
start_instrumentation
does effectively nothing and stop_instrumentation
will stop the
event counting as requested. This is most likely not what you intended. The event counting
should start with start_instrumentation
. To achieve this, you can set EntryPoint::None
which removes the default toggle, but also --collect-at-start=no
. So, you need to specify
--collect-at-start=no
in LibraryBenchmarkConfig::callgrind_args
. The example would
then look like this:
use std::hint::black_box;
use iai_callgrind::{library_benchmark, EntryPoint, LibraryBenchmarkConfig};
// ...
#[library_benchmark(
config = LibraryBenchmarkConfig::default()
.callgrind_args(["--collect-at-start=no"])
.entry_point(EntryPoint::None)
)]
fn some_bench() -> u64 {
black_box(to_be_benchmarked())
}
// ...
sourcepub fn output_format<T>(&mut self, output_format: T) -> &mut Selfwhere
T: Into<InternalOutputFormat>,
pub fn output_format<T>(&mut self, output_format: T) -> &mut Selfwhere
T: Into<InternalOutputFormat>,
Configure the crate::OutputFormat
of the terminal output of Iai-Callgrind
§Examples
use iai_callgrind::{main, LibraryBenchmarkConfig, OutputFormat};
main!(
config = LibraryBenchmarkConfig::default()
.output_format(OutputFormat::default()
.truncate_description(Some(200))
);
library_benchmark_groups = some_group
);
Trait Implementations§
source§impl AsRef<LibraryBenchmarkConfig> for LibraryBenchmarkConfig
impl AsRef<LibraryBenchmarkConfig> for LibraryBenchmarkConfig
source§fn as_ref(&self) -> &InternalLibraryBenchmarkConfig
fn as_ref(&self) -> &InternalLibraryBenchmarkConfig
source§impl Clone for LibraryBenchmarkConfig
impl Clone for LibraryBenchmarkConfig
source§fn clone(&self) -> LibraryBenchmarkConfig
fn clone(&self) -> LibraryBenchmarkConfig
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for LibraryBenchmarkConfig
impl Debug for LibraryBenchmarkConfig
source§impl Default for LibraryBenchmarkConfig
impl Default for LibraryBenchmarkConfig
source§fn default() -> LibraryBenchmarkConfig
fn default() -> LibraryBenchmarkConfig
source§impl From<&LibraryBenchmarkConfig> for InternalLibraryBenchmarkConfig
impl From<&LibraryBenchmarkConfig> for InternalLibraryBenchmarkConfig
source§fn from(value: &LibraryBenchmarkConfig) -> Self
fn from(value: &LibraryBenchmarkConfig) -> Self
source§impl From<&mut LibraryBenchmarkConfig> for InternalLibraryBenchmarkConfig
impl From<&mut LibraryBenchmarkConfig> for InternalLibraryBenchmarkConfig
source§fn from(value: &mut LibraryBenchmarkConfig) -> Self
fn from(value: &mut LibraryBenchmarkConfig) -> Self
source§impl From<LibraryBenchmarkConfig> for InternalLibraryBenchmarkConfig
impl From<LibraryBenchmarkConfig> for InternalLibraryBenchmarkConfig
source§fn from(value: LibraryBenchmarkConfig) -> Self
fn from(value: LibraryBenchmarkConfig) -> Self
Auto Trait Implementations§
impl Freeze for LibraryBenchmarkConfig
impl RefUnwindSafe for LibraryBenchmarkConfig
impl Send for LibraryBenchmarkConfig
impl Sync for LibraryBenchmarkConfig
impl Unpin for LibraryBenchmarkConfig
impl UnwindSafe for LibraryBenchmarkConfig
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)