When you have a problem with a slow app, first of all, you need to find which exact parts of your code are taking quite a lot of processing time. A good way of finding such parts of the code, which are also called bottlenecks, is to profile the app. One of the good profilers available that allow an app to be profiled without modifications being introduced to the app is called pyinstrument (https://github.com/joerick/pyinstrument). Here, we profile the app of Chapter 10, Learning to Detect and Track Objects, using pyinstrument, as follows:
$ pyinstrument -o profile.html -r html main.py
We have passed an output .html file where we want the profiling report information to be saved with a -o option.
We have also specified how the report should be rendered with a -r option, to state that we want an HTML output. Once the app is terminated, the...