【发布时间】:2016-05-03 06:45:30
【问题描述】:
我试图了解使用 time.timer 运行一个函数需要多长时间,但我真的不知道如何实现它,我认为这会起作用:
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 的运行时间,有人能告诉我怎么做吗?我一直觉得这并不难,但我不知道怎么做。
【问题讨论】:
标签: python time timer runtime execution