pub struct FuchsiaCriterion { /* private fields */ }
Expand description
Thin wrapper around Criterion
.
Implementations§
Source§impl FuchsiaCriterion
impl FuchsiaCriterion
Sourcepub fn fuchsia_bench() -> Self
pub fn fuchsia_bench() -> Self
Creates a new Criterion
object whose output is tailored to Fuchsia-CI.
It calls its Default::default
constructor with 10,000 resamples, then looks for a CMD
argument providing the path for JSON file where the micro-benchmark results should be
written (in the Fuchsiaperf file format).
Sourcepub fn fuchsia_bench_with_args(args: &[&str]) -> Self
pub fn fuchsia_bench_with_args(args: &[&str]) -> Self
Same as fuchsia_bench()
, but parses the specified args instead of parsing
std::env::args
.
This is useful when the benchmarks needs to accept some arguments specified in the CML file.
Methods from Deref<Target = Criterion>§
Sourcepub fn bench_function<F>(&mut self, id: &str, f: F) -> &mut Criterion
pub fn bench_function<F>(&mut self, id: &str, f: F) -> &mut Criterion
Benchmarks a function
§Example
fn bench(c: &mut Criterion) {
// Setup (construct data, allocate memory, etc)
c.bench_function(
"function_name",
|b| b.iter(|| {
// Code to benchmark goes here
}),
);
}
criterion_group!(benches, bench);
criterion_main!(benches);
Sourcepub fn bench_functions<I>(
&mut self,
id: &str,
funs: Vec<Fun<I>>,
input: I,
) -> &mut Criterionwhere
I: Debug + 'static,
pub fn bench_functions<I>(
&mut self,
id: &str,
funs: Vec<Fun<I>>,
input: I,
) -> &mut Criterionwhere
I: Debug + 'static,
Benchmarks multiple functions
All functions get the same input and are compared with the other implementations.
Works similar to bench_function
, but with multiple functions.
§Example
fn bench_seq_fib(b: &mut Bencher, i: &u32) {
b.iter(|| {
seq_fib(i);
});
}
fn bench_par_fib(b: &mut Bencher, i: &u32) {
b.iter(|| {
par_fib(i);
});
}
fn bench(c: &mut Criterion) {
let sequential_fib = Fun::new("Sequential", bench_seq_fib);
let parallel_fib = Fun::new("Parallel", bench_par_fib);
let funs = vec![sequential_fib, parallel_fib];
c.bench_functions("Fibonacci", funs, 14);
}
criterion_group!(benches, bench);
criterion_main!(benches);
Sourcepub fn bench_function_over_inputs<I, F>(
&mut self,
id: &str,
f: F,
inputs: I,
) -> &mut Criterionwhere
I: IntoIterator,
<I as IntoIterator>::Item: Debug + 'static,
F: FnMut(&mut Bencher, &<I as IntoIterator>::Item) + 'static,
pub fn bench_function_over_inputs<I, F>(
&mut self,
id: &str,
f: F,
inputs: I,
) -> &mut Criterionwhere
I: IntoIterator,
<I as IntoIterator>::Item: Debug + 'static,
F: FnMut(&mut Bencher, &<I as IntoIterator>::Item) + 'static,
Benchmarks a function under various inputs
This is a convenience method to execute several related benchmarks. Each benchmark will
receive the id: ${id}/${input}
.
§Example
fn bench(c: &mut Criterion) {
c.bench_function_over_inputs("from_elem",
|b: &mut Bencher, size: &usize| {
b.iter(|| vec![0u8; *size]);
},
vec![1024, 2048, 4096]
);
}
criterion_group!(benches, bench);
criterion_main!(benches);
Sourcepub fn bench_program(&mut self, id: &str, program: Command) -> &mut Criterion
👎Deprecated since 0.2.6: External program benchmarks were rarely used and are awkward to maintain, so they are scheduled for deletion in 0.3.0
pub fn bench_program(&mut self, id: &str, program: Command) -> &mut Criterion
Benchmarks an external program
The external program must:
- Read the number of iterations from stdin
- Execute the routine to benchmark that many times
- Print the elapsed time (in nanoseconds) to stdout
// Example of an external program that implements this protocol
fn main() {
let stdin = io::stdin();
let ref mut stdin = stdin.lock();
// For each line in stdin
for line in stdin.lines() {
// Parse line as the number of iterations
let iters: u64 = line.unwrap().trim().parse().unwrap();
// Setup
// Benchmark
let start = Instant::now();
// Execute the routine "iters" times
for _ in 0..iters {
// Code to benchmark goes here
}
let elapsed = start.elapsed();
// Teardown
// Report elapsed time in nanoseconds to stdout
println!("{}", elapsed.to_nanos());
}
}
Sourcepub fn bench_program_over_inputs<I, F>(
&mut self,
id: &str,
program: F,
inputs: I,
) -> &mut Criterion
👎Deprecated since 0.2.6: External program benchmarks were rarely used and are awkward to maintain, so they are scheduled for deletion in 0.3.0
pub fn bench_program_over_inputs<I, F>( &mut self, id: &str, program: F, inputs: I, ) -> &mut Criterion
Benchmarks an external program under various inputs
This is a convenience method to execute several related benchmarks. Each benchmark will
receive the id: ${id}/${input}
.
Sourcepub fn bench<B>(&mut self, group_id: &str, benchmark: B) -> &mut Criterionwhere
B: BenchmarkDefinition,
pub fn bench<B>(&mut self, group_id: &str, benchmark: B) -> &mut Criterionwhere
B: BenchmarkDefinition,
Executes the given benchmark. Use this variant to execute benchmarks with complex configuration. This can be used to compare multiple functions, execute benchmarks with custom configuration settings and more. See the Benchmark and ParameterizedBenchmark structs for more information.
fn bench(c: &mut Criterion) {
// Setup (construct data, allocate memory, etc)
c.bench(
"routines",
Benchmark::new("routine_1", |b| b.iter(|| routine_1()))
.with_function("routine_2", |b| b.iter(|| routine_2()))
.sample_size(50)
);
}
criterion_group!(benches, bench);
criterion_main!(benches);
Trait Implementations§
Source§impl Default for FuchsiaCriterion
impl Default for FuchsiaCriterion
Source§impl Deref for FuchsiaCriterion
impl Deref for FuchsiaCriterion
Source§impl DerefMut for FuchsiaCriterion
impl DerefMut for FuchsiaCriterion
Source§impl Drop for FuchsiaCriterion
impl Drop for FuchsiaCriterion
Source§fn drop(&mut self)
fn drop(&mut self)
Drops the Criterion
wrapper.
If initialized with FuchsiaCriterion::fuchsia_bench
, it will write the Fuchsia-specific
JSON file before dropping.
Auto Trait Implementations§
impl Freeze for FuchsiaCriterion
impl !RefUnwindSafe for FuchsiaCriterion
impl !Send for FuchsiaCriterion
impl !Sync for FuchsiaCriterion
impl Unpin for FuchsiaCriterion
impl !UnwindSafe for FuchsiaCriterion
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more