pub trait Measurement {
    type Intermediate;
    type Value;

    // Required methods
    fn start(&self) -> Self::Intermediate;
    fn end(&self, i: Self::Intermediate) -> Self::Value;
    fn add(&self, v1: &Self::Value, v2: &Self::Value) -> Self::Value;
    fn zero(&self) -> Self::Value;
    fn to_f64(&self, value: &Self::Value) -> f64;
    fn formatter(&self) -> &dyn ValueFormatter;
}
Expand description

Trait for all types which define something Criterion.rs can measure. The only measurement currently provided is WallTime, but third party crates or benchmarks may define more.

This trait defines two core methods, start and end. start is called at the beginning of a measurement to produce some intermediate value (for example, the wall-clock time at the start of that set of iterations) and end is called at the end of the measurement with the value returned by start.

Required Associated Types§

source

type Intermediate

This type represents an intermediate value for the measurements. It will be produced by the start function and passed to the end function. An example might be the wall-clock time as of the start call.

source

type Value

This type is the measured value. An example might be the elapsed wall-clock time between the start and end calls.

Required Methods§

source

fn start(&self) -> Self::Intermediate

Criterion.rs will call this before iterating the benchmark.

source

fn end(&self, i: Self::Intermediate) -> Self::Value

Criterion.rs will call this after iterating the benchmark to get the measured value.

source

fn add(&self, v1: &Self::Value, v2: &Self::Value) -> Self::Value

Combine two values. Criterion.rs sometimes needs to perform measurements in multiple batches of iterations, so the value from one batch must be added to the sum of the previous batches.

source

fn zero(&self) -> Self::Value

Return a “zero” value for the Value type which can be added to another value.

source

fn to_f64(&self, value: &Self::Value) -> f64

Converts the measured value to f64 so that it can be used in statistical analysis.

source

fn formatter(&self) -> &dyn ValueFormatter

Return a trait-object reference to the value formatter for this measurement.

Implementors§