stdlib.bench¶
Timing and throughput harnesses for micro- and macro-benchmarks.
Generated from
v0.60.1. 1 source files, 17 documented symbols.
bench.xi¶
type BenchResult¶
Timing result of one benchmark run.
| Field | Type |
|---|---|
name |
Str |
iterations |
Int |
total_ns |
Int |
mean_ns |
Int |
min_ns |
Int |
max_ns |
Int |
stddev_ns |
Int |
Derives: Clone
fn run_bench(name: Str, f: fn() -> Unit) -> BenchResult¶
Time
fonce and return the result.
- Precondition:
name.len() > 0
fn run_bench_n(name: Str, iterations: Int, f: fn() -> Unit) -> BenchResult¶
Time
foveriterationsruns; returns aggregate stats.
- Precondition:
name.len() > 0 - Precondition:
iterations >= 0 - Postcondition:
result.iterations == iterations
fn compare(a: BenchResult, b: BenchResult) -> Str¶
Human-readable comparison of two benchmark results.
- Postcondition:
result.len() > 0
fn black_box[T](value: T) -> T¶
Opaque identity that prevents the optimizer from eliding the value.
fn bench_ops_per_sec_ns(result: &BenchResult) -> Int¶
Returns operations per second based on
mean_ns. Returns 0 ifmean_nsis 0 to avoid division by zero. Complexity: O(1). Pure.
fn bench_faster_percent(baseline: &BenchResult, candidate: &BenchResult) -> Int¶
Returns how many percent
candidateis faster thanbaseline. Positive means candidate is faster. Formula: (base - cand) * 100 / base. Returns 0 ifbaseline.mean_nsis 0. Complexity: O(1). Pure.
fn bench_min_ns(results: Vec[BenchResult]) -> Int¶
Returns the minimum
mean_nsacross all benchmark results. Returns 0 if the vector is empty. Complexity: O(n).
fn bench_max_ns(results: Vec[BenchResult]) -> Int¶
Returns the maximum
mean_nsacross all benchmark results. Returns 0 if the vector is empty. Complexity: O(n).
fn bench_total_ns(results: Vec[BenchResult]) -> Int¶
Returns the sum of
total_nsacross all benchmark results. Complexity: O(n).
fn bench_median_ns(results: Vec[BenchResult]) -> Int¶
Returns the median
mean_nsacross results (middle element by position, unsorted). Complexity: O(1) index access.
fn bench_human_ns(ns: Int) -> Str¶
Converts nanoseconds to a human-readable string ("1.23ms", "45us", "100ns"). Complexity: O(1).
fn bench_black_box_int(n: Int) -> Int¶
Wraps
black_boxforIntvalues, preventing compiler optimisations from eliminating benchmarked computations. Complexity: O(1). Pure.
fn bench_run_avg(name: Str, iterations: Int, f: fn() -> Unit) -> BenchResult¶
Runs a benchmark with the given name and iteration count. Alias for
run_bench_n. Complexity: runsfexactlyiterationstimes.
fn bench_time_fn(f: fn() -> Unit) -> Int¶
Times a single invocation of
fand returns the elapsed nanoseconds. Complexity: runsfexactly once.
fn bench_report(results: Vec[BenchResult]) -> Str¶
Generates a table report with columns: name, mean, min, max, ops/s. Complexity: O(n).
fn bench_report_simple(results: Vec[BenchResult]) -> Str¶
Generates a compact one-line-per-result report. Complexity: O(n).