MCPcopy Create free account
hub / github.com/ShivaBhattacharjee/KeyZen / timer

Function timer

data/python/05_decorators.py:3–10  ·  view source on GitHub ↗
(func)

Source from the content-addressed store, hash-verified

1import time
2
3def timer(func):
4 def wrapper(*args, **kwargs):
5 start = time.time()
6 result = func(*args, **kwargs)
7 end = time.time()
8 print(f"{func.__name__} took {end - start:.4f}s")
9 return result
10 return wrapper
11
12@timer
13def heavy_computation(n):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected