Created
October 9, 2015 15:37
-
-
Save lizhongz/8e6e9bb642424d10dc74 to your computer and use it in GitHub Desktop.
Python Execution Time Decorator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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