Skip to content

Instantly share code, notes, and snippets.

@po5i
Created December 18, 2020 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save po5i/f68325e213b040d98b2d74133701c951 to your computer and use it in GitHub Desktop.
Save po5i/f68325e213b040d98b2d74133701c951 to your computer and use it in GitHub Desktop.
Time measure decorator for Python
from functools import wraps
from time import process_time
def measure(func):
@wraps(func)
def _time_it(*args, **kwargs):
start = int(round(process_time() * 1000))
try:
return func(*args, **kwargs)
finally:
end_ = int(round(process_time() * 1000)) - start
print(
f"Total execution time {func.__name__}: {end_ if end_ > 0 else 0} ms"
)
return _time_it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment