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萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章