Profiling Python Code
Profiling is a technique to figure out how time is spent in a program. With these statistics, we can find the “hot spot” of a program and think about ways of improvement. Sometimes, a hot spot in an unexpected location may hint at a bug in the program as well.
In this tutorial, we will see how we can use the profiling facility in Python. Specifically, you will see:
- How we can compare small code fragments using the
timeit
module - How we can profile the entire program using the
cProfile
module - How we can invoke a profiler inside an existing program
- What the profiler cannot do
Kick-start your project with my new book Python for Machine Learning, including