Skip to main content
Log in

Mojo struct

Bencher

Defines a Bencher struct which facilitates the timing of a target function.

Fields​

  • ​num_iters (Int): Number of iterations to run the target function.
  • ​elapsed (Int): The total time elpased when running the target function.

Implemented traits​

AnyType, Copyable, Movable

Methods​

__init__​

__init__(inout self: Self, num_iters: Int)

Constructs a Bencher object to run and time a function.

Args:

  • ​num_iters (Int): Number of times to run the target function.

iter​

iter[iter_fn: fn() capturing -> None](inout self: Self)

Returns the total elapsed time by running a target function a particular number of times.

Parameters:

  • ​iter_fn (fn() capturing -> None): The target function to benchmark.

iter[iter_fn: fn() raises capturing -> None](inout self: Self)

Returns the total elapsed time by running a target function a particular number of times.

Parameters:

  • ​iter_fn (fn() raises capturing -> None): The target function to benchmark.

iter_preproc​

iter_preproc[iter_fn: fn() capturing -> None, preproc_fn: fn() capturing -> None](inout self: Self)

Returns the total elapsed time by running a target function a particular number of times.

Parameters:

  • ​iter_fn (fn() capturing -> None): The target function to benchmark.
  • ​preproc_fn (fn() capturing -> None): The function to preprocess the target function.

iter_custom​

iter_custom[iter_fn: fn(Int) capturing -> Int](inout self: Self)

Times a target function with custom number of iterations.

Parameters:

  • ​iter_fn (fn(Int) capturing -> Int): The target function to benchmark.

iter_custom[kernel_launch_fn: fn(DeviceContext) raises capturing -> None](inout self: Self, ctx: DeviceContext)

Times a target GPU function with custom number of iterations via DeviceContext ctx.

Parameters:

  • ​kernel_launch_fn (fn(DeviceContext) raises capturing -> None): The target GPU kernel launch function to benchmark.

Args:

  • ​ctx (DeviceContext): The GPU DeviceContext for launching kernel.

iter_custom[kernel_launch_fn: fn(DeviceContext, Int) raises capturing -> None](inout self: Self, ctx: DeviceContext)

Times a target GPU function with custom number of iterations via DeviceContext ctx.

Parameters:

  • ​kernel_launch_fn (fn(DeviceContext, Int) raises capturing -> None): The target GPU kernel launch function to benchmark.

Args:

  • ​ctx (DeviceContext): The GPU DeviceContext for launching kernel.

iter_custom[iter_fn: fn(Int) raises capturing -> Int](inout self: Self)

Times a target function with custom number of iterations.

Parameters:

  • ​iter_fn (fn(Int) raises capturing -> Int): The target function to benchmark.

Was this page helpful?