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?
Thank you! We'll create more content like this.
Thank you for helping us improve!
π What went wrong?