python统计程序运行时间函数

统计程序运行时间是time.clock()
装饰器的参数 (*args, **kwargs)

import time
def decorated_hello(func):
def _hello(*args, **kwargs):
    print "<function name : " +func.__name__+">"
    print "<function call begin>"
    #start = time.time()
    func(*args, **kwargs)
    #end = time.time() - start
    print "<function call end>"
    print "[timecosts: %s]" % time.clock()
return _hello

@decorated_hello
def hello(name):
    print "hello, %s" % name
#time.sleep(1)
hello("Richard")
发布了289 篇原创文章 · 获赞 280 · 访问量 130万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章