相关疑难解决方法(0)

在Python 2.7中获得执行代码块的时间

我想测量在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
Run Code Online (Sandbox Code Playgroud)

用户和系统CPU时间不是必需的(虽然我想测量它们),但是对于经过的时间我希望能够做这样的事情,而不是使用复杂的命令或模块.

python profiler python-2.7

67
推荐指数
4
解决办法
8万
查看次数

标签 统计

profiler ×1

python ×1

python-2.7 ×1