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: StringStable name of the benchmark.
samples: Vec<Duration>All raw sample durations.
iterations_recorded: u64Total 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: DurationSum of all sample durations.
mean: DurationMean sample duration.
p50: Duration50th percentile sample duration.
p99: Duration99th percentile sample duration.
cv: f64Coefficient 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
impl BenchmarkResult
Sourcepub fn ops_per_sec(&self) -> f64
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);Sourcepub fn stddev(&self) -> f64
pub fn stddev(&self) -> f64
Sample standard deviation, in seconds. 0.0 for fewer than 2 samples.
Uses n-1 (Bessel’s correction) for the sample variance.
Sourcepub fn mad(&self) -> f64
pub fn mad(&self) -> f64
Median absolute deviation, in seconds. 0.0 for empty results.
MAD = median(|x_i - median(x)|). Less affected by outliers than
standard deviation; useful for noisy measurements.
Sourcepub fn p90(&self) -> Duration
pub fn p90(&self) -> Duration
90th percentile sample duration. Duration::ZERO for empty results.
Sourcepub fn p999(&self) -> Duration
pub fn p999(&self) -> Duration
99.9th percentile sample duration. Duration::ZERO for empty results.
At least 1000 samples are required to be meaningful; with fewer samples this returns the largest sample.
Sourcepub fn percentile(&self, q: f64) -> Duration
pub fn percentile(&self, q: f64) -> Duration
Compute an arbitrary percentile (0.0..=1.0). Returns Duration::ZERO
for empty results. Uses nearest-rank, the same as p50/p99.
Sourcepub fn histogram(&self, bucket_count: usize) -> Vec<HistogramBin>
pub fn histogram(&self, bucket_count: usize) -> Vec<HistogramBin>
Compute a uniform-width histogram over the sample distribution.
Returns bucket_count bins covering [min, max], each with
the count of samples falling into that bin. The returned
Vec<HistogramBin> is in ascending order; the first bin’s
lower equals min(), the last bin’s upper equals max().
For an empty result or bucket_count == 0, returns vec![].
When min == max (all samples equal), returns one bin with
the full sample count.
Useful for spotting bimodality, outlier tails, and warmup effects that mean/percentile alone hide.
§Example
use dev_bench::Benchmark;
let mut b = Benchmark::new("h");
for _ in 0..50 { b.iter(|| std::hint::black_box(1 + 1)); }
let r = b.finish();
let hist = r.histogram(8);
assert!(hist.len() <= 8);
let total: usize = hist.iter().map(|h| h.count).sum();
assert_eq!(total, r.samples.len());Sourcepub fn compare_against_baseline(
&self,
baseline_mean: Option<Duration>,
threshold: Threshold,
) -> CheckResult
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),
);Sourcepub fn compare_with_options(&self, opts: &CompareOptions) -> CheckResult
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->Skipwith detail. - Within threshold ->
Passwith 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);Sourcepub fn into_report(
self,
subject_version: impl Into<String>,
baseline_mean: Option<Duration>,
threshold: Threshold,
) -> Report
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
impl Clone for BenchmarkResult
Source§fn clone(&self) -> BenchmarkResult
fn clone(&self) -> BenchmarkResult
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more