【发布时间】:2013-03-20 09:06:33
【问题描述】:
我想测量在 Python 程序中评估一段代码所用的时间, 可能在用户 cpu 时间、系统 cpu 时间和经过时间之间分开。
我知道timeit模块,但是我有很多自己写的函数,不是很容易
在设置过程中传递它们。
我宁愿有一些可以像这样使用的东西:
#up to here I have done something....
start_counting() #or whatever command used to mark that I want to measure
#the time elapsed in the next rows
# code I want to evaluate
user,system,elapsed = stop_counting() #or whatever command says:
#stop the timer and return the times
用户和系统 CPU 时间并不重要(尽管我想测量它们), 但是在过去的时间里,我希望能够做这样的事情, 而不是使用复杂的命令或模块。
【问题讨论】:
标签: python python-2.7 profiler