【发布时间】:2016-06-27 15:36:23
【问题描述】:
我正在尝试在我的 python 脚本上运行 cProfile,我只关心运行的总时间。有没有办法修改
python -m cProfile myscript.py
所以输出就是总时间?
【问题讨论】:
标签: python command-line-arguments cprofile
我正在尝试在我的 python 脚本上运行 cProfile,我只关心运行的总时间。有没有办法修改
python -m cProfile myscript.py
所以输出就是总时间?
【问题讨论】:
标签: python command-line-arguments cprofile
这个答案假设您使用的是 Unix 终端。 我能想到的最快的事情是使用 ">" 运算符将结果重定向到一个文件中,然后用 head 读取文件,例如:
python -m cProfile your_python_file.py > temp_file && head -n 3 temp_file
所以基本上,为了进一步解释我自己,您正在将分析的所有结果写入 temp_file (如果该文件不存在并且它的名称并不重要,则会创建该文件)。在此之后,您使用 head -n 3 显示此文件的前 3 行。当然,如果您不需要 temp_file,您将不得不手动删除它!希望这会有所帮助!
【讨论】: