Exercise 19. Improving Performance
This is a mostly video exercise where I will demonstrate improving the performance of the code you’ve written so far, but first you should attempt it. You’ve analyzed how slow and fast the code is from Exercise 18, so now it’s time to implement some of your ideas. I’ll give you a quick list of things to look for and change when fixing simple performance problems:
1. Loops inside loops repeating calculations that can be avoided. The bubble sort is the classic case of this, and that’s why I taught it. Once you can see how terrible bubble sort is compared to other methods you’ll start to recognize this as a common pattern to avoid.
2. Repeatedly calculating something that doesn’t really change or can be calculated ...
Get Learn More Python 3 the Hard Way: The Next Step for New Python Programmers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.