Only cProfile
gave us comprehensive information about the performance of all functions in the asa.py
file. However, what happens if you want to drill down further and understand the performance of each line in the Python code? Robert Kern's line_profiler
module is a Python module that enables you to do just this, and this is exactly the level of detail that you want for this chapter.
The installation and setup of the line profiler is a little bit more complicated than usual, so we will discuss this in the next recipe.
The steps that are listed will introduce you to profiling with the line_profiler
module:
To use the
line_profiler
module, we must first install it using thepip
command:(sudo) pip install line_profiler
Next, we want to grab the
kernprof.py
Python script from the website (http://pythonhosted.org/line_profiler/) and place it in the directory where we are runningasa.py
.Open the
asa.py
script in your favorite editor...