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§
Sourcetype Intermediate
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.
Required Methods§
Sourcefn start(&self) -> Self::Intermediate
fn start(&self) -> Self::Intermediate
Criterion.rs will call this before iterating the benchmark.
Sourcefn end(&self, i: Self::Intermediate) -> Self::Value
fn end(&self, i: Self::Intermediate) -> Self::Value
Criterion.rs will call this after iterating the benchmark to get the measured value.
Sourcefn add(&self, v1: &Self::Value, v2: &Self::Value) -> Self::Value
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.
Sourcefn zero(&self) -> Self::Value
fn zero(&self) -> Self::Value
Return a “zero” value for the Value type which can be added to another value.
Sourcefn to_f64(&self, value: &Self::Value) -> f64
fn to_f64(&self, value: &Self::Value) -> f64
Converts the measured value to f64 so that it can be used in statistical analysis.
Sourcefn formatter(&self) -> &dyn ValueFormatter
fn formatter(&self) -> &dyn ValueFormatter
Return a trait-object reference to the value formatter for this measurement.