我試圖去理解它需要多長時間功能使用time.timer運行的運行時間,但我真的難倒如何實現它我想這會工作:使用定時器獲得funtion
def breadth_first_tree_search(problem):
"Search the shallowest nodes in the search tree first."
t1 = timeit.Timer(lambda: problem)
n = 1
secs = t1.timeit(number = n)
print ("\n%d times took %8f seconds" % (n,secs))
return tree_search(problem, FIFOQueue())
但後來我意識到它的時機是錯誤的。 我需要它來檢查運行時間breadth_first_tree_search
有人可以告訴我該怎麼做,我一直覺得它不是那麼辛苦,但我不知道如何。
'了time.time()'可能比'timeit不太精確.default_timer()'在Windows上。請參見[測量Python中的時間?](http://stackoverflow.com/a/25823885/4279) – jfs