Skip to main content

Mojo struct

Bench

Defines the main Benchmark struct which executes a Benchmark and print result.

Fields

  • config (BenchConfig): Constructs a Benchmark object based on specific configuration and mode.
  • mode (Mode): Benchmark mode object representing benchmark or test mode.
  • info_vec (List[BenchmarkInfo]): A list containing the bencmark info.

Implemented traits

AnyType, UnknownDestructibility

Methods

__init__

__init__(out self, config: Optional[BenchConfig] = Optional(None), mode: Mode = 0)

Constructs a Benchmark object based on specific configuration and mode.

Args:

  • config (Optional[BenchConfig]): Benchmark configuration object to control length and frequency of benchmarks.
  • mode (Mode): Benchmark mode object representing benchmark or test mode.

bench_with_input

bench_with_input[: origin.set, //, T: AnyType, bench_fn: fn(inout Bencher, $1|1) raises capturing -> None](inout self, bench_id: BenchId, input: T, measures: List[ThroughputMeasure] = List())

Benchmarks an input function with input args of type AnyType.

Parameters:

  • T (AnyType): Benchmark function input type.
  • bench_fn (fn(inout Bencher, $1|1) raises capturing -> None): The function to be benchmarked.

Args:

  • bench_id (BenchId): The benchmark Id object used for identification.
  • input (T): Represents the target function's input arguments.
  • measures (List[ThroughputMeasure]): Optional arg used to represent a list of ThroughputMeasure's.

bench_with_input[: origin.set, //, T: AnyType, bench_fn: fn(inout Bencher, $1|1) raises capturing -> None](inout self, bench_id: BenchId, input: T, *measures: ThroughputMeasure)

Benchmarks an input function with input args of type AnyType.

Parameters:

  • T (AnyType): Benchmark function input type.
  • bench_fn (fn(inout Bencher, $1|1) raises capturing -> None): The function to be benchmarked.

Args:

  • bench_id (BenchId): The benchmark Id object used for identification.
  • input (T): Represents the target function's input arguments.
  • *measures (ThroughputMeasure): Variadic arg used to represent a list of ThroughputMeasure's.

bench_with_input[: origin.set, //, T: AnyTrivialRegType, bench_fn: fn(inout Bencher, $1|1) raises capturing -> None](inout self, bench_id: BenchId, input: T, measures: List[ThroughputMeasure] = List())

Benchmarks an input function with input args of type AnyTrivialRegType.

Parameters:

  • T (AnyTrivialRegType): Benchmark function input type.
  • bench_fn (fn(inout Bencher, $1|1) raises capturing -> None): The function to be benchmarked.

Args:

  • bench_id (BenchId): The benchmark Id object used for identification.
  • input (T): Represents the target function's input arguments.
  • measures (List[ThroughputMeasure]): Optional arg used to represent a list of ThroughputMeasure's.

bench_with_input[: origin.set, //, T: AnyTrivialRegType, bench_fn: fn(inout Bencher, $1|1) raises capturing -> None](inout self, bench_id: BenchId, input: T, *measures: ThroughputMeasure)

Benchmarks an input function with input args of type AnyTrivialRegType.

Parameters:

  • T (AnyTrivialRegType): Benchmark function input type.
  • bench_fn (fn(inout Bencher, $1|1) raises capturing -> None): The function to be benchmarked.

Args:

  • bench_id (BenchId): The benchmark Id object used for identification.
  • input (T): Represents the target function's input arguments.
  • *measures (ThroughputMeasure): Variadic arg used to represent a list of ThroughputMeasure's.

bench_function

bench_function[: origin.set, //, bench_fn: fn(inout Bencher) capturing -> None](inout self, bench_id: BenchId, measures: List[ThroughputMeasure] = List())

Benchmarks or Tests an input function.

Parameters:

  • bench_fn (fn(inout Bencher) capturing -> None): The function to be benchmarked.

Args:

  • bench_id (BenchId): The benchmark Id object used for identification.
  • measures (List[ThroughputMeasure]): Optional arg used to represent a list of ThroughputMeasure's.

bench_function[: origin.set, //, bench_fn: fn(inout Bencher) capturing -> None](inout self, bench_id: BenchId, *measures: ThroughputMeasure)

Benchmarks or Tests an input function.

Parameters:

  • bench_fn (fn(inout Bencher) capturing -> None): The function to be benchmarked.

Args:

  • bench_id (BenchId): The benchmark Id object used for identification.
  • *measures (ThroughputMeasure): Variadic arg used to represent a list of ThroughputMeasure's.

bench_function[: origin.set, //, bench_fn: fn(inout Bencher) raises capturing -> None](inout self, bench_id: BenchId, measures: List[ThroughputMeasure] = List())

Benchmarks or Tests an input function.

Parameters:

  • bench_fn (fn(inout Bencher) raises capturing -> None): The function to be benchmarked.

Args:

  • bench_id (BenchId): The benchmark Id object used for identification.
  • measures (List[ThroughputMeasure]): Optional arg used to represent a list of ThroughputMeasure's.

bench_function[: origin.set, //, bench_fn: fn(inout Bencher) raises capturing -> None](inout self, bench_id: BenchId, *measures: ThroughputMeasure)

Benchmarks or Tests an input function.

Parameters:

  • bench_fn (fn(inout Bencher) raises capturing -> None): The function to be benchmarked.

Args:

  • bench_id (BenchId): The benchmark Id object used for identification.
  • *measures (ThroughputMeasure): Variadic arg used to represent a list of ThroughputMeasure's.

dump_report

dump_report(self)

Prints out the report from a Benchmark execution.