Skip to main content

BenchmarkResult

Struct BenchmarkResult 

Source
pub struct BenchmarkResult {
    pub name: String,
    pub samples: Vec<Duration>,
    pub iterations_recorded: u64,
    pub total_elapsed: Duration,
    pub mean: Duration,
    pub p50: Duration,
    pub p99: Duration,
    pub cv: f64,
}
Expand description

The result of a finished benchmark.

Statistics are computed losslessly from the raw samples.

§Example

use dev_bench::Benchmark;

let mut b = Benchmark::new("noop");
for _ in 0..10 {
    b.iter(|| std::hint::black_box(42));
}
let r = b.finish();
assert!(r.mean.as_nanos() > 0);

Fields§

§name: String

Stable name of the benchmark.

§samples: Vec<Duration>

All raw sample durations.

§iterations_recorded: u64

Total iterations across all samples. With per-iter sampling this equals samples.len(). With batched sampling, it is the sum of n across all iter_with_count calls.

§total_elapsed: Duration

Sum of all sample durations.

§mean: Duration

Mean sample duration.

§p50: Duration

50th percentile sample duration.

§p99: Duration

99th percentile sample duration.

§cv: f64

Coefficient of variation across samples (stddev / mean).

Higher numbers indicate noisier measurements. A CV of 0.05 means the standard deviation is 5% of the mean. Reported regressions within the CV are downgraded from Fail to Warn by compare_with_options.

Implementations§

Source§

impl BenchmarkResult

Source

pub fn ops_per_sec(&self) -> f64

Effective throughput in operations per second.

Defined as iterations_recorded / total_elapsed_seconds. Returns 0.0 for an empty result or zero elapsed time.

§Example
use dev_bench::Benchmark;

let mut b = Benchmark::new("hot");
b.iter_with_count(1000, || { std::hint::black_box(1 + 1); });
let r = b.finish();
assert!(r.ops_per_sec() > 0.0);
Source

pub fn compare_against_baseline( &self, baseline_mean: Option<Duration>, threshold: Threshold, ) -> CheckResult

Compare this result against a baseline using a default-tuned CompareOptions.

baseline_mean is the previous mean duration. If None, the verdict is Skip and no comparison is made.

§Example
use dev_bench::{Benchmark, Threshold};
use std::time::Duration;

let mut b = Benchmark::new("x");
b.iter(|| std::hint::black_box(1 + 1));
let r = b.finish();
let _ = r.compare_against_baseline(
    Some(Duration::from_nanos(1)),
    Threshold::regression_pct(10.0),
);
Source

pub fn compare_with_options(&self, opts: &CompareOptions) -> CheckResult

Compare this result against a baseline using full options.

Behavior:

  • No baseline -> Skip.
  • Sample count below min_samples -> Skip with detail.
  • Within threshold -> Pass with numeric evidence.
  • Over threshold but within CV noise band -> Warn.
  • Over threshold and outside CV noise band -> Fail (Warning).

In every non-Skip case, the returned CheckResult carries a bench tag and numeric Evidence for mean_ns, baseline_ns, p50_ns, p99_ns, cv, and ops_per_sec.

§Example
use dev_bench::{Benchmark, CompareOptions, Threshold};
use std::time::Duration;

let mut b = Benchmark::new("x");
b.iter(|| std::hint::black_box(1 + 1));
let r = b.finish();
let opts = CompareOptions {
    baseline_mean: Some(Duration::from_nanos(1)),
    threshold: Threshold::regression_pct(20.0),
    min_samples: 1,
    allow_cv_noise_band: true,
};
let _check = r.compare_with_options(&opts);
Source

pub fn into_report( self, subject_version: impl Into<String>, baseline_mean: Option<Duration>, threshold: Threshold, ) -> Report

Build a one-check Report containing the comparison result.

Convenience for producers that want a complete Report rather than a single CheckResult. Sets subject = self.name, producer = "dev-bench".

§Example
use dev_bench::{Benchmark, Threshold};

let mut b = Benchmark::new("x");
b.iter(|| std::hint::black_box(1 + 1));
let r = b.finish();
let report = r.into_report("0.1.0", None, Threshold::regression_pct(10.0));
assert_eq!(report.checks.len(), 1);

Trait Implementations§

Source§

impl Clone for BenchmarkResult

Source§

fn clone(&self) -> BenchmarkResult

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BenchmarkResult

Source§

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

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.