Skip to content

Instantly share code, notes, and snippets.

@fmasanori
Created May 21, 2013 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fmasanori/5620010 to your computer and use it in GitHub Desktop.
Save fmasanori/5620010 to your computer and use it in GitHub Desktop.
Time decorator
import time
from functools import wraps
def tempo(func):
@wraps(func)
def wrapper(*args, **kwargs):
t1 = time.time()
result = func(*args, **kwargs)
t2 = time.time()
print(func.__name__, t2 - t1)
return result
return wrapper
@tempo
def contador(n):
while n > 0: n -= 1
contador(1000000)
contador(10000000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment