Python Performance Profiling: The Guts And The Glory01:45 PM - 02:10 PM on July 16, 2016, Room CR4
- Audience level:
Your Python program is too slow, and you need to optimize it. Where do you start? Optimization is a scientific investigation, just like debugging is: you generate hypotheses about how to make your program faster, then use benchmarks as the experiments that test your hypotheses. With the right tools, you can optimize your code where it counts. With the Python profiler “Yappi” to understand its features and limitations we’ll learn how to find the maximum performance wins with minimum effort.
I'll describe three open-source profilers for Python, and explain why Yappi is the right profiler for this job.
Optimization is like debugging: we use the scientific method. We form a hypothesis about what changes we can make to our code to make it faster, and we estimate how much improvement an optimization can yield. Then comes the second part of the scientific method: we test the hypothesis with an experiment.
And now, let's return to the problem at hand: Is my code slow? We'll use Yappi to form some hypotheses, then validate them with tests. Finally, I have an answer to my boss's question, and better yet, I can back up my answer with hard evidence.