Skip to content

Instantly share code, notes, and snippets.

@secantsquared
Created July 10, 2020 00:17
Show Gist options
  • Select an option

  • Save secantsquared/791c9121bae7875b001f7e75f23a7e8c to your computer and use it in GitHub Desktop.

Select an option

Save secantsquared/791c9121bae7875b001f7e75f23a7e8c to your computer and use it in GitHub Desktop.
simple decorator to approximate run time for basic functions
import time
from functools import wraps
def timeit(func):
@wraps(func)
def wrapper(*args, **kwargs):
t_initial = time.perf_counter()
value = func(*args, **kwargs)
t_final = time.perf_counter() - t_initial
print(f"{func.__name__!r} finished in {t_final-t_initial:0.4f} secs.")
return value
return wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment