Skip to content Skip to sidebar Skip to footer

Cprofile Command Line How To Reduce Output

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 jus

Solution 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!

Post a Comment for "Cprofile Command Line How To Reduce Output"