Created
May 21, 2024 16:41
-
-
Save sboysel/78170db6c3e2ab17a6904ba6599ee548 to your computer and use it in GitHub Desktop.
simple timer function decorator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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