Use profiler in Python

I use it once in a while, but I forget how to use it soon.

Take a profile in the program or on the interpreter. If you want to take a profile of a function with some_command:

import cProfile
cProfile.run('some_command()', 'spam.prf')

Take a profile from the command line. If you want to profile the execution of a file called do.py:

$ python -m stats -o spam.prf do.py

Each proifle is stored in spam.prf.

View profile results.

$ python -m pstats spam.prf
spam.prf% stats

Recommended Posts

Use profiler in Python
Use config.ini in Python
Use dates in Python
Use Valgrind in Python
Use let expression in Python
Use Measurement Protocol in Python
Use callback function in Python
Use parameter store in Python
Use HTTP cache in Python
Use MongoDB ODM in Python
Use list-keyed dict in Python
Use Random Forest in Python
Use Spyder in Python IDE
Use fabric as is in python (fabric3)
How to use SQLite in Python
Use rospy with virtualenv in Python3
How to use Mysql in python
Use Python in pyenv with NeoVim
How to use ChemSpider in Python
How to use PubChem in Python
Use OpenCV with Python 3 in Window
Quadtree in Python --2
Python in optimization
CURL in python
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python