Skip to main content

Benchmark

Trait Benchmark 

Source
pub trait Benchmark: 'static {
    type Input: Input + 'static;
    type Output: Serialize;

    // Required methods
    fn try_match(&self, input: &Self::Input, context: &MatchContext) -> Score;
    fn description(&self, f: &mut Formatter<'_>) -> Result;
    fn run(
        &self,
        input: &Self::Input,
        checkpoint: Checkpoint<'_>,
        output: &mut dyn Output,
    ) -> Result<Self::Output>;
}
Expand description

A registered benchmark.

Benchmarks consist of an Input and a corresponding serialized Output. Inputs will first be validated with the benchmark using try_match. Only successful matches will be passed to run.

Required Associated Types§

Source

type Input: Input + 'static

The Input type this benchmark matches against.

Source

type Output: Serialize

The concrete type of the results generated by this benchmark.

Required Methods§

Source

fn try_match(&self, input: &Self::Input, context: &MatchContext) -> Score

Return whether or not this benchmark is compatible with input.

Use MatchContext::success to create an initial Score, then progressively refine it with Score::penalize and Score::fail.

Among successful matches, the benchmark with the lowest score wins. Ties are broken by an unspecified procedure.

When no successful match exists, failure scores rank the “nearest misses”. Implementations should use Score::fail with descriptive reasons to aid diagnostics.

Source

fn description(&self, f: &mut Formatter<'_>) -> Result

Return descriptive information about the benchmark.

Source

fn run( &self, input: &Self::Input, checkpoint: Checkpoint<'_>, output: &mut dyn Output, ) -> Result<Self::Output>

Run the benchmark with input.

All prints should be directed to output. The checkpoint is provided so long-running benchmarks can periodically save output to prevent data loss due to an early error.

Implementors may assume that Self::try_match returned a successful Score for input.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§