cProfile命令行如何减少输出 [英] cProfile command line how to reduce output
问题描述
我正在尝试在python脚本上运行cProfile,我关心的只是运行所花费的总时间。有没有办法修改
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
所以输出只是总时间?
推荐答案
该答案假设您正在使用Unix终端。
我能想到的最快的方法是使用>运算符将结果重定向到文件中,然后用head读取文件,例如:
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
基本上,为了进一步解释我自己,您正在写所有剖析到temp_file(如果该文件不存在并且其名称并不重要,则将创建该文件)。然后,使用 head -n 3
显示该文件的前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!
这篇关于cProfile命令行如何减少输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!