Optimize your code using profilers
Profiling is a type of runtime analysis that operates on large amounts of runtime data and gives you a view of what is happening inside a process. The collected data relates to various aspects of program operation, such as CPU usage, percentage of memory allocation, and threads' activity.
PyCharm allows running the current run/debug configuration while attaching a Python profiler to it. Note that the Diagrams plugin that is bundled with PyCharm should be enabled.
If you have a yappi profiler installed on your interpreter, PyCharm starts the profiling session with it by default; otherwise it uses the standard cProfile profiler.
Besides these two tracing profilers, PyCharm supports also sampling (statistical) profiler vmprof, which should be installed on the selected Python interpreter. If you are Windows 64 bit user, you have to install Python 32 bit, to make vmprof work. Install 32-bit Python as described on the page Python Releases for Windows.
A profiler is selected in the following order: vmprof, yappi, cProfile.
When is profiling helpful?
Profiling tools help you:
Identify bugs, bottlenecks and diagnose poor performance
Identify hot spots and opportunities for optimization (not necessarily related to a performance problem)
Assess or compare the performance of different solutions
Get a better understanding of how a program operates under the hood
Start the profiling session
Click More Actions on the main toolbar and select .
Ensure that the profiler has started in the dedicated tab of the Run tool window.
Read the profiler snapshot.