modularml / mojo

The Mojo Programming Language
https://docs.modular.com/mojo/manual/
Other
23.28k stars 2.59k forks source link

[Feature Request] Measuring allocations + wall time for functions #125

Closed sa- closed 4 months ago

sa- commented 1 year ago

Request

When writing code with performance in mind, keeping an eye on the number of allocations + time taken is crucial to know. This is a feature request to provide a decorator/macro that provides this information.

Motivation

Julia has solved this problem quite well and it would be nice to have this in mojo somehow This is how Julia provides this information

 julia> @time some_function()
 # output: 0.000091 seconds (3.49 k allocations: 70.156 KiB)

I've found it to be a very pragmatic way to shorten the feedback loop when writing performant code. Allows for faster coding iteration times by making it easy to measure performance.

Description and Requirements

Not sure how this would be implemented since decorators and macros are not implemented yet, maybe this is a feature request for a future point in time. Wanted to express my interest in this sort of feature anyway

strangemonad commented 1 year ago

@sa- I also definitely want some way to do timing and benchmarking but in general find both julia's @time and python's @timeit a bit too crude. Workflows, e.g. notebooks often run in cloud environments with variable wall clock time and other clock issues that come from running in VMs.

I wonder if there might be a better way to instrument program counters instead to be able to probe cpu instructions, syscalls, allocations etc.

Microbenchmarks also usually need special attention. The prior art with JMH (the java microbenchmark harness), HDR histogram, and scalene are also great design points

walter-erquinigo commented 4 months ago

Thank you for reporting this. For the time being we won't be adding this feature, but we might revisit it next year.