cProfile command line how to reduce output

可紊 提交于 2020-01-24 13:24:26

问题


I'm trying to run cProfile on my python script and all I care about is the total time it took to run. Is there a way to modify

python -m cProfile myscript.py

so the output is just the total time?


回答1:


This answers supposes that you are using a Unix terminal. The fastest thing I can think of would be to redirect the results into a file with the ">" operator and then read the file with head, something like:

python -m cProfile your_python_file.py > temp_file && head -n 3 temp_file 

So basically, to explain my self further, you are writing all the results of the profiling into temp_file (this file will get created if it doesn't exist and its name does not really matter ). And after this you display the first 3 lines of this file with head -n 3 . Of course you will have to manually delete temp_file if you do not need it! Hope this helps!



来源:https://stackoverflow.com/questions/38058016/cprofile-command-line-how-to-reduce-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!