Skip to main content

FuchsiaCriterion

Struct FuchsiaCriterion 

Source
pub struct FuchsiaCriterion { /* private fields */ }
Expand description

Thin wrapper around Criterion.

Implementations§

Source§

impl FuchsiaCriterion

Source

pub fn new(criterion: Criterion) -> Self

Creates a new Criterion wrapper.

Source

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).

Source

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>§

Source

pub fn benchmark_group<S>(&mut self, group_name: S) -> BenchmarkGroup<'_, M>
where S: Into<String>,

Return a benchmark group. All benchmarks performed using a benchmark group will be grouped together in the final report.

§Examples:
use criterion::{criterion_group, criterion_main, Criterion};

fn bench_simple(c: &mut Criterion) {
    let mut group = c.benchmark_group("My Group");

    // Now we can perform benchmarks with this group
    group.bench_function("Bench 1", |b| b.iter(|| 1 ));
    group.bench_function("Bench 2", |b| b.iter(|| 2 ));

    group.finish();
}
criterion_group!(benches, bench_simple);
criterion_main!(benches);
§Panics:

Panics if the group name is empty

Source

pub fn bench_function<F>(&mut self, id: &str, f: F) -> &mut Criterion<M>
where F: FnMut(&mut Bencher<'_, M>),

Benchmarks a function. For comparing multiple functions, see benchmark_group.

§Example
use criterion::{criterion_group, criterion_main, Criterion};

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);
Source

pub fn bench_with_input<F, I>( &mut self, id: BenchmarkId, input: &I, f: F, ) -> &mut Criterion<M>
where F: FnMut(&mut Bencher<'_, M>, &I),

Benchmarks a function with an input. For comparing multiple functions or multiple inputs, see benchmark_group.

§Example
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};

fn bench(c: &mut Criterion) {
    // Setup (construct data, allocate memory, etc)
    let input = 5u64;
    c.bench_with_input(
        BenchmarkId::new("function_name", input), &input,
        |b, i| b.iter(|| {
            // Code to benchmark using input `i` goes here
        }),
    );
}

criterion_group!(benches, bench);
criterion_main!(benches);

Trait Implementations§

Source§

impl Default for FuchsiaCriterion

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Deref for FuchsiaCriterion

Source§

type Target = Criterion

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for FuchsiaCriterion

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl Drop for FuchsiaCriterion

Source§

fn drop(&mut self)

Drops the Criterion wrapper.

If initialized with FuchsiaCriterion::fuchsia_bench, it will write the Fuchsia-specific JSON file before dropping.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.