[root@node110 decorator]# cat temp_decorator.py
#!/usr/bin/env python
import time
def time_counter(func):
def wrapper():
start =time.time()
func()
end =time.time()
print 'Thisfunction costs:',end-start
return wrapper
#sayhi=time_counter(sayhi)
#sayhi()
@time_counter
#相当于sayhi=time_counter(sayhi)
#sayhi()
def sayhi():
print 'hi yoursister...'
time.sleep(0.1)
@time_counter
def tellyoursalary():
print 'Allenmakes 25k per month...'
sayhi()
tellyoursalary()