Mojo struct
Bencher
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 elapsed when running the target function.
Implemented traits
AnyType,
ImplicitlyDestructible,
Movable,
RegisterPassable
Methods
__init__
__init__(num_iters: Int) -> Self
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: def() capturing -> None](mut self)
Returns the total elapsed time by running a target function a particular number of times.
Parameters:
- iter_fn (
def() capturing -> None): The target function to benchmark.
iter[IterFn: def() -> None](mut self, f: IterFn)
Returns the total elapsed time by running a target closure a particular number of times.
Parameters:
- IterFn (
def() -> None): Type of the closure to benchmark.
Args:
- f (
IterFn): The closure to benchmark.
iter[iter_fn: def() raises capturing -> None](mut self)
Returns the total elapsed time by running a target function a particular number of times.
Parameters:
- iter_fn (
def() raises capturing -> None): The target function to benchmark.
Raises:
If the operation fails.
iter_preproc
iter_preproc[iter_fn: def() capturing -> None, preproc_fn: def() capturing -> None](mut self)
Returns the total elapsed time by running a target function a particular number of times.
Parameters:
- iter_fn (
def() capturing -> None): The target function to benchmark. - preproc_fn (
def() capturing -> None): The function to preprocess the target function.
iter_preproc[IterFn: def() -> None, PreprocFn: def() -> None](mut self, iter_fn: IterFn, preproc_fn: PreprocFn)
Returns the total elapsed time by running a target function a particular number of times.
Parameters:
- IterFn (
def() -> None): The target function type. - PreprocFn (
def() -> None): The preprocess function type.
Args:
- iter_fn (
IterFn): The closure carrying the captured state of the target function. - preproc_fn (
PreprocFn): The closure carrying the captured state of the preprocess function.
iter_custom
iter_custom[iter_fn: def(Int) raises capturing -> Int](mut self)
Times a target function with custom number of iterations.
Parameters:
- iter_fn (
def(Int) raises capturing -> Int): The target function to benchmark.
iter_custom[FuncType: def(Int) -> Int](mut self, func: FuncType)
Times a target function with custom number of iterations.
Parameters:
- FuncType (
def(Int) -> Int): The target function type.
Args:
- func (
FuncType): The closure carrying the captured state of the target function.
iter_custom[kernel_launch_fn: def(DeviceContext) raises capturing -> None](mut self, ctx: DeviceContext)
Times a target GPU function with custom number of iterations via DeviceContext ctx.
Parameters:
- kernel_launch_fn (
def(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: def(DeviceContext, Int) raises capturing -> None](mut self, ctx: DeviceContext)
Times a target GPU function with custom number of iterations via DeviceContext ctx.
Parameters:
- kernel_launch_fn (
def(DeviceContext, Int) raises capturing -> None): The target GPU kernel launch function to benchmark.
Args:
- ctx (
DeviceContext): The GPU DeviceContext for launching kernel.
iter_custom_multicontext
iter_custom_multicontext[kernel_launch_fn: def() raises capturing -> None](mut self, ctxs: List[DeviceContext])
Times a target GPU function with custom number of iterations via DeviceContext ctx.
Parameters:
- kernel_launch_fn (
def() raises capturing -> None): The target GPU kernel launch function to benchmark.
Args:
- ctxs (
List): The list of GPU DeviceContext's for launching kernel.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!