IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: Nightly
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

QuickBench

struct QuickBench

Defines a struct to facilitate benchmarking and avoiding Bencher boilerplate.

Fields​

  • ​m (Bench): Bench object to collect the results.

Implemented traits​

AnyType, Deinitable, Movable

Methods​

__init__​

def __init__(out self)

Initializes the Bench object.

Raises:

If the operation fails.

dump_report​

def dump_report(mut self)

Prints out the report from a Benchmark execution collected in Bench object.

Raises:

If the operation fails.

run​

def run[T_out: TrivialRegisterPassable, //](mut self, func: T, *, bench_id: BenchId, measures: List[ThroughputMeasure] = List())

Benchmarks func, keeping its result alive so the call is not optimized away.

To benchmark a function that takes arguments, wrap the call in a closure that captures them.

Examples:

from std.benchmark import BenchId, QuickBench
from std.math import exp

var qb = QuickBench()
var x: Float32 = 1.0
qb.run(lambda () {x} -> Float32: exp(x), bench_id=BenchId("exp"))
qb.dump_report()

Parameters:

Args:

  • ​func (T): The function to be benchmarked (run in benchmark iterations).
  • ​bench_id (BenchId): The benchmark Id object used for identification.
  • ​measures (List[ThroughputMeasure]): Optional arg used to represent a list of ThroughputMeasure's.

Raises:

If the operation fails.

def run(mut self, func: T, *, bench_id: BenchId, measures: List[ThroughputMeasure] = List())

Benchmarks func, which returns nothing.

Args:

  • ​func (T): The function to be benchmarked (run in benchmark iterations).
  • ​bench_id (BenchId): The benchmark Id object used for identification.
  • ​measures (List[ThroughputMeasure]): Optional arg used to represent a list of ThroughputMeasure's.

Raises:

If the operation fails.