pub struct BinaryBenchmark {
pub id: BenchmarkId,
pub config: Option<InternalBinaryBenchmarkConfig>,
pub benches: Vec<Bench>,
pub setup: Option<fn()>,
pub teardown: Option<fn()>,
}
default
only.Expand description
low level api only: Mirror the crate::binary_benchmark
attribute
A BinaryBenchmark
can be created in two ways. Either with BinaryBenchmark::new
. Or via the
crate::binary_benchmark_attribute
macro used with a function annotated with the
crate::binary_benchmark
attribute. So, you can start with the high-level api using the
attribute and then go on in the low-level api.
§Examples
For examples using BinaryBenchmark::new
, see there. Here’s an example using the
crate::binary_benchmark_attribute
use iai_callgrind::{
binary_benchmark, binary_benchmark_group, binary_benchmark_attribute, Bench
};
#[binary_benchmark]
#[bench::foo("foo")]
fn bench_binary(arg: &str) -> iai_callgrind::Command {
iai_callgrind::Command::new(env!("CARGO_BIN_EXE_my-foo"))
.arg(arg)
.build()
}
binary_benchmark_group!(
name = my_group;
benchmarks = |group: &mut BinaryBenchmarkGroup| {
let mut binary_benchmark = binary_benchmark_attribute!(bench_binary);
// Continue and add another `Bench` to the `BinaryBenchmark`
binary_benchmark.bench(Bench::new("bar")
.command(iai_callgrind::Command::new(env!("CARGO_BIN_EXE_my-foo"))
.arg("bar")
)
);
// Finally, add the `BinaryBenchmark` to the group
group
.binary_benchmark(binary_benchmark);
}
);
Fields§
§id: BenchmarkId
An id which has to be unique within the same BinaryBenchmarkGroup
In the high-level api this is the name of the function which is annotated by
crate::binary_benchmark
config: Option<InternalBinaryBenchmarkConfig>
An optional BinaryBenchmarkConfig
which is applied to all Command
s within this
BinaryBenchmark
benches: Vec<Bench>
All Bench
es which were added to this BinaryBenchmark
setup: Option<fn()>
The default setup
function for all Bench
es within this BinaryBenchmark
. It can be
overwritten in a Bench
teardown: Option<fn()>
The default teardown
function for all Bench
es within this BinaryBenchmark
. It can
be overwritten in a Bench
Implementations§
source§impl BinaryBenchmark
impl BinaryBenchmark
sourcepub fn new<T>(id: T) -> Selfwhere
T: Into<BenchmarkId>,
pub fn new<T>(id: T) -> Selfwhere
T: Into<BenchmarkId>,
Create a new BinaryBenchmark
A BinaryBenchmark
is the equivalent of the
#[binary_benchmark]
attribute in the low-level api and needs
a BenchmarkId
. In the high-level api the id is derived from the function name.
The BenchmarkId
is used together with the id of each Bench
to create a directory
name. This usually limits the combined length of the ids to 255 - 1
but can be less
depending on the file system. See BenchmarkId
for more details
§Scope of uniqueness of the BenchmarkId
The id needs to be unique within the same crate::binary_benchmark_group
. It is
recommended to use an id which is unique within the whole benchmark file, although doing
otherwise does currently not incur any negative consequence.
§Examples
use iai_callgrind::{BenchmarkId, BinaryBenchmark};
let binary_benchmark = BinaryBenchmark::new("some_id");
assert_eq!(binary_benchmark.id, BenchmarkId::new("some_id"));
sourcepub fn config<T>(&mut self, config: T) -> &mut Selfwhere
T: Into<InternalBinaryBenchmarkConfig>,
pub fn config<T>(&mut self, config: T) -> &mut Selfwhere
T: Into<InternalBinaryBenchmarkConfig>,
Add a BinaryBenchmarkConfig
to this BinaryBenchmark
§Examples
use iai_callgrind::{BinaryBenchmark, BinaryBenchmarkConfig};
let binary_benchmark = BinaryBenchmark::new("some_id")
.config(BinaryBenchmarkConfig::default().env("FOO", "BAR"))
.clone();
assert_eq!(
binary_benchmark.config,
Some(BinaryBenchmarkConfig::default().env("FOO", "BAR").into())
);
sourcepub fn bench<T>(&mut self, bench: T) -> &mut Self
pub fn bench<T>(&mut self, bench: T) -> &mut Self
Add a Bench
to this BinaryBenchmark
Adding a Bench
which doesn’t contain a Command
is an error.
§Examples
use iai_callgrind::{Bench, BinaryBenchmark, Command};
// Each `Bench` needs at least one `Command`!
let mut bench = Bench::new("some_id");
bench.command(Command::new(env!("CARGO_BIN_EXE_my-echo")));
let binary_benchmark = BinaryBenchmark::new("bench_binary")
.bench(bench.clone())
.clone();
assert_eq!(binary_benchmark.benches[0], bench);
sourcepub fn setup(&mut self, setup: fn()) -> &mut Self
pub fn setup(&mut self, setup: fn()) -> &mut Self
Add a setup
function to this BinaryBenchmark
This setup
function is used in all Bench
es of this BinaryBenchmark
if not overridden
by the Bench
.
§Examples
use iai_callgrind::Bench;
fn my_setup() {
println!(
"Place everything in this function you want to be executed before the execution of \
the Command"
);
}
let bench = Bench::new("some_id").setup(my_setup).clone();
assert!(bench.setup.is_some())
Overwrite the setup function from this BinaryBenchmark
in a Bench
use iai_callgrind::{Bench, BinaryBenchmark};
fn binary_benchmark_setup() {
println!("setup in BinaryBenchmark")
}
fn bench_setup() {
println!("setup in Bench")
}
BinaryBenchmark::new("bench_binary")
.setup(binary_benchmark_setup)
.bench(Bench::new("some_id").setup(bench_setup));
sourcepub fn teardown(&mut self, teardown: fn()) -> &mut Self
pub fn teardown(&mut self, teardown: fn()) -> &mut Self
Add a teardown
function to this BinaryBenchmark
This teardown
function is used in all Bench
es of this BinaryBenchmark
if not
overridden by the Bench
.
§Examples
use iai_callgrind::Bench;
fn my_teardown() {
println!(
"Place everything in this function you want to be executed after the execution of the \
Command"
);
}
let bench = Bench::new("some_id").teardown(my_teardown).clone();
assert!(bench.teardown.is_some())
Overwrite the teardown function from this BinaryBenchmark
in a Bench
use iai_callgrind::{Bench, BinaryBenchmark};
fn binary_benchmark_teardown() {
println!("teardown in BinaryBenchmark")
}
fn bench_teardown() {
println!("teardown in Bench")
}
BinaryBenchmark::new("bench_binary")
.teardown(binary_benchmark_teardown)
.bench(Bench::new("some_id").teardown(bench_teardown));
Trait Implementations§
source§impl Clone for BinaryBenchmark
impl Clone for BinaryBenchmark
source§fn clone(&self) -> BinaryBenchmark
fn clone(&self) -> BinaryBenchmark
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for BinaryBenchmark
impl Debug for BinaryBenchmark
source§impl From<&BinaryBenchmark> for BinaryBenchmark
impl From<&BinaryBenchmark> for BinaryBenchmark
source§fn from(value: &BinaryBenchmark) -> Self
fn from(value: &BinaryBenchmark) -> Self
source§impl From<&mut BinaryBenchmark> for BinaryBenchmark
impl From<&mut BinaryBenchmark> for BinaryBenchmark
source§fn from(value: &mut BinaryBenchmark) -> Self
fn from(value: &mut BinaryBenchmark) -> Self
source§impl PartialEq for BinaryBenchmark
impl PartialEq for BinaryBenchmark
impl StructuralPartialEq for BinaryBenchmark
Auto Trait Implementations§
impl Freeze for BinaryBenchmark
impl RefUnwindSafe for BinaryBenchmark
impl Send for BinaryBenchmark
impl Sync for BinaryBenchmark
impl Unpin for BinaryBenchmark
impl UnwindSafe for BinaryBenchmark
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
)