Benchmark

Module

Implements the Benchmark class for runtime benchmarking.

Benchmark

A benchmark harness.

The class allows to benchmark a given function (passed as a parameter) and configure various benchmarking parameters, such as number of warmup iterations, maximum number of iterations, minimum and maximum elapsed time.

Fields:

max_iters

The maximum number of iterations to perform during the main benchmark loop.

max_time_ns

The maximum time (in ns) to spend within the main benchmark loop.

min_time_ns

The minimum time (in ns) to spend within the main benchmark loop.

num_warmup

The number of warmup iterations to perform before the main benchmark loop.

Functions:

__init__

__init__(self: Self&, num_warmup: Int, max_iters: Int, min_time_ns: Int, max_time_ns: Int)

Constructs a new benchmark object.

Given a function the benchmark object will benchmark it until min_tims_ns has elapsed and either max_time_ns OR max_iters is hit.

Args:

  • num_warmup (Int): Number of warmup iterations to run before starting benchmarking (default 2).
  • max_iters (Int): Max number of iterations to run (default 100_000).
  • min_time_ns (Int): Upper bound on benchmarking time in ns (default 500ms).
  • max_time_ns (Int): Lower bound on benchmarking time in ns (default 1s).

__copyinit__

__copyinit__(self: Self&, existing: Self)

__moveinit__

__moveinit__(self: Self&, existing: Self)

run

run[func: fn() capturing -> None](self: Self) -> Int

Benchmark the given function.

Benchmarking continues until min_tims_ns has elapsed and either max_time_ns or max_iters is achieved.

Parameters:

  • func (fn() capturing -> None): The function to benchmark.

Returns:

Average execution time of func in ns.