Created
June 21, 2021 00:16
-
-
Save lcsbossle/24c6e50208d21837bd8b053639944920 to your computer and use it in GitHub Desktop.
Timer decorator for python functions
This file contains hidden or 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 timed(func): | |
def function_timer(*args, **kwargs): | |
start = time.time() | |
result = func(*args, **kwargs) | |
end = time.time() | |
runtime = (end - start)*1000 | |
message = f"Function [{func.__name__}] executed in {runtime} ms" | |
print(message) | |
return result | |
return function_timer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment