Skip to content

Instantly share code, notes, and snippets.

@lizhongz
Created October 9, 2015 15:37
Show Gist options
  • Save lizhongz/8e6e9bb642424d10dc74 to your computer and use it in GitHub Desktop.
Save lizhongz/8e6e9bb642424d10dc74 to your computer and use it in GitHub Desktop.
Python Execution Time Decorator
def exec_time(func):
def inner(*args, **kwargs):
import time
st = time.time()
ret = func(*args, **kwargs)
et = time.time() - st
print "execution time %s seconds" %(et)
return ret
return inner
@exec_time
def fabonacci(n):
if n == 0:
return 0
elif n == 1:
return 1
a, b = 0, 1
i = 2
while i < n:
a, b = b, a + b
i += 1
return b
if __name__ == "__main__":
print fabonacci(20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment