mojo icon indicating copy to clipboard operation
mojo copied to clipboard

[Feature Request] `%%timeit` magic function in notebook cells for benchmarking

Open moflo opened this issue 1 year ago • 3 comments

Request

Add support for import time or %time (%timeit) magic function

Motivation

Performance claim challenge

Description and Requirements

Update the Mandelbrot notebook to display execution time using whatever method is easiest for you to support.

moflo avatar May 12 '23 03:05 moflo

Also, the Benchmark being used in the examples on playground to compute time is unclear. Does it need to wrap the function being called into another function for benchmarking?

falaktheoptimist avatar May 14 '23 10:05 falaktheoptimist

Also, the Benchmark being used in the examples on playground to compute time is unclear. Does it need to wrap the function being called into another function for benchmarking?

It appears so. The Benchmark.run() function is parameterized by a function with a fixed signature which is

func: fn() capturing -> None

Even if the function you are benchmarking has the same signature, it might not be possible to call it directly from Benchmark.run() because of the requirement of the function being "capturing". So at the moment it seems to be a requirement to do it that way. I think by adding the @always_inline decorator we are avoiding the costs of those wrapper function calls, so we don't need to worry about it impacting the actual measurements being made by the benchmark.

abhinav-upadhyay avatar May 17 '23 06:05 abhinav-upadhyay

We already have from Time import now, which isn't quite the same as Python's time module, but you can always import that via the Python interop API. Retitling this to the special %%timeit command.

Mogball avatar May 18 '23 03:05 Mogball