Module std::bench

Benchmark harness for measuring function performance.

Provides a simple API for timing function execution with nanosecond precision, warm-up iterations, and formatted output.

Examples

import std::bench;

fn main() {
    let s = bench.suite("My Benchmarks");
    s.add("fib_20", 1000, || { fibonacci(20); });
    s.report();
}

Contents

Functions

Function suite

pub fn suite(name: string) -> Suite

Create a new benchmark suite.

Types

Struct BenchResult

A single benchmark result containing timing statistics.

Fields

name: string
iterations: i64
avg_ns: i64
min_ns: i64
max_ns: i64
total_ns: i64

Struct Suite

A collection of benchmark results.

Fields

name: string
results: Vec<BenchResult>

Traits

Trait SuiteMethods

Methods available on a benchmark Suite.

Methods

fn add(self: Self, name: string, iterations: i64, f: fn() -> ())

Run a benchmark and record the result.

Executes f for iterations times after a warmup phase (10% of iterations, minimum 1). Records min, max, avg, and total timing in nanoseconds.

fn report(self: Self)

Print results as a human-readable table.

fn report_json(self: Self)

Print results as a JSON array.