Skip to content

Instantly share code, notes, and snippets.

@r3dm1ke
Created August 6, 2020 14:47
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 r3dm1ke/3679e3152c13f4c8f681458fa140a7af to your computer and use it in GitHub Desktop.
Save r3dm1ke/3679e3152c13f4c8f681458fa140a7af to your computer and use it in GitHub Desktop.
def timer_decorator(func):
def timer_wrapper(*args, **kwargs):
import datetime
before = datetime.datetime.now()
result = func(*args,**kwargs)
after = datetime.datetime.now()
print "Elapsed Time = {0}".format(after-before)
return result
@timer_decorator
def sum(x, y):
print(x + y)
return x + y
sum(2, 5)
> 7
> Elapsed Time = some time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment