Module testing/bench
testing/bench
Micro-benchmarking utilities.
Runs a function N times, measures elapsed nanoseconds, and returns statistics (average, min, max).
Example
{ bench } :: import "std/testing/bench";
result := bench(`sort`, u64(1000), () => { /* work */ });
println(result.to_string());
Types
BenchResult
struct
BenchResult
Timing statistics returned by bench.
Fields
| Name | Type | Description |
|---|---|---|
name | String | Benchmark name. |
iterations | u64 | Total number of iterations executed. |
total_ns | i64 | Total elapsed nanoseconds across all iterations. |
avg_ns | i64 | Average nanoseconds per iteration. |
min_ns | i64 | Minimum nanoseconds for a single iteration. |
max_ns | i64 | Maximum nanoseconds for a single iteration. |
Trait Implementations
impl(BenchResult, ToString(...))
to_string : (fn(self: *(Self)) -> String)Returns: String
Functions
bench
function
fn(name : String, iterations : u64, body : Impl(Fn() -> unit)) -> BenchResult
Run body for iterations times and return timing statistics.
Parameters
| Name | Type | Notes | Description |
|---|---|---|---|
name | String | Benchmark name. | |
iterations | u64 | Total number of iterations executed. | |
body | Impl(Fn() -> unit) |
Returns: BenchResult