Skip to main content

Benchmark

Trait Benchmark 

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

    // Required methods
    fn try_match(input: &Self::Input) -> Result<MatchScore, FailureScore>;
    fn description(f: &mut Formatter<'_>, input: Option<&Self::Input>) -> Result;
    fn run(
        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(input: &Self::Input) -> Result<MatchScore, FailureScore>

Return whether or not this benchmark is compatible with input.

On success, returns Ok(MatchScore). MatchScores of all benchmarks will be collected and the benchmark with the lowest final score will be selected.

In the case of ties, the winner is chosen using an unspecified tie-breaking procedure.

On failure, returns Err(FailureScore). In the crate::registry::Benchmarks registry, FailureScores will be used to rank the “nearest misses”. Implementations are encouraged to generate ranked FailureScores to assist in user level debugging.

Source

fn description(f: &mut Formatter<'_>, input: Option<&Self::Input>) -> Result

Return descriptive information about the benchmark.

If input is None, then high level information about the benchmark should be relayed. If input is Some, and is an unsuccessful match, diagnostic information about what was expected should be generated to help users.

Source

fn run( 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 Ok on input.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§