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.

Function format_time

fn format_time(ns: i64) -> String

Format a nanosecond duration as a human-readable string with appropriate units.

Function format_ops

fn format_ops(avg_ns: i64) -> String

Format an average nanosecond duration as an operations-per-second string.

Function pad_two

fn pad_two(n: i64) -> String

Pad a number to two digits with a leading zero if needed.

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: Suite, name: String, iterations: i64, f: fn() -> ()) fn report(self: Suite) fn report_json(self: Suite)