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 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