Created
February 10, 2014 09:45
-
-
Save neojou/8913103 to your computer and use it in GitHub Desktop.
Python 裝飾器 @
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
import time | |
def timeusage(func): | |
def call(*args, **kwargs): | |
start = time.clock() | |
print func(*args, **kwargs) | |
end = time.clock() | |
return "Time costs : %s . " % (end - start ) | |
return call | |
@timeusage | |
def factorial(n): | |
y=1 | |
for i in range(n, 0, -1): | |
y = y * i | |
return y | |
print factorial(10) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment