Skip to content

Instantly share code, notes, and snippets.

@sboysel
Created May 21, 2024 16:41
Show Gist options
  • Save sboysel/78170db6c3e2ab17a6904ba6599ee548 to your computer and use it in GitHub Desktop.
Save sboysel/78170db6c3e2ab17a6904ba6599ee548 to your computer and use it in GitHub Desktop.
simple timer function decorator
import time
def timer(f):
"""
timer function decorator. Prints time elapsed (in seconds) of the function's
runttime.
Usage:
@timer
def my_function():
...
"""
def _f():
begin = time.perf_counter()
f()
end = time.perf_counter()
print(f"Time elapsed: {end - begin}")
return _f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment