"Is this faster?" is one of the most common questions in ML systems work — is this kernel fusion actually helping, does this batch size change hurt throughput, is the new data loader really the bottleneck. Answering it requires measuring, not guessing, and measuring the same way every time a function is called quickly becomes tedious to write by hand at every call site.
Implement timed(func), a decorator that wraps any function so that calling the wrapped version runs the original function and returns (result, elapsed_seconds) instead of just result — one reusable measurement tool instead of hand-rolled timing code scattered everywhere.
timed(func) returns a new callable with the same calling convention as func (same positional and keyword arguments).(original_result, elapsed_seconds).elapsed_seconds is measured using a monotonic, high-resolution clock — never negative, never affected by system clock changes.func's __name__ and docstring (via functools.wraps).Open one at a time. Each gives away a little more than the last.
time.perf_counter() is Python's monotonic, high-resolution timer — call it once immediately before running func, and once immediately after, then subtract.
@wraps(func) from functools, applied to your inner wrapper function, is what makes the wrapped function keep func's real __name__ and docstring instead of showing wrapper everywhere.
No results yet
Run your code to check it against the examples, or submit to run every test.