Skip to content

Instantly share code, notes, and snippets.

@lcsbossle
Created June 21, 2021 00:16
Show Gist options
  • Save lcsbossle/24c6e50208d21837bd8b053639944920 to your computer and use it in GitHub Desktop.
Save lcsbossle/24c6e50208d21837bd8b053639944920 to your computer and use it in GitHub Desktop.
Timer decorator for python functions
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