我在一个文件中有一个Python脚本,运行时间超过30秒.我试图描述它,因为我想大幅削减这一次.
我试图使用脚本来编写脚本cProfile,但基本上所有它似乎都在告诉我是的,主脚本需要很长时间才能运行,但是没有给出我期望的那种故障.在终端,我键入如下内容:
cat my_script_input.txt | python -m cProfile -s time my_script.py
Run Code Online (Sandbox Code Playgroud)
我得到的结果是:
<my_script_output>
683121 function calls (682169 primitive calls) in 32.133 seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
1 31.980 31.980 32.133 32.133 my_script.py:18(<module>)
121089 0.050 0.000 0.050 0.000 {method 'split' of 'str' objects}
121090 0.038 0.000 0.049 0.000 fileinput.py:243(next)
2 0.027 0.014 0.036 0.018 {method 'sort' of 'list' objects}
121089 0.009 0.000 0.009 0.000 {method 'strip' of 'str' objects}
201534 0.009 0.000 0.009 …Run Code Online (Sandbox Code Playgroud)