Skip to content

Instantly share code, notes, and snippets.

@neojou
Created February 10, 2014 09:45
Show Gist options
  • Save neojou/8913103 to your computer and use it in GitHub Desktop.
Save neojou/8913103 to your computer and use it in GitHub Desktop.
Python 裝飾器 @
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