The goal of this post and its predecessor is to provide some tools and tips for improving the performance of Python programs. In the previous post , we examined profiling tools — sophisticated stopwatches for timing programs as they execute. In this post, we will use these tools to demonstrate some general principles that make Python programs run faster. Remember: If your program already runs fast enough, you do not need to worry about profiling and optimization. Faster is not always better, especially if you end up with code that is difficult to read, modify, or maintain. Overview We can summarize our principles for optimizing performance as follows: Debug first. Never attempt to optimize a program that does not work. Focus on bottlenecks. Find out what takes the most time, and work on that. Look for algorithmic improvements. A different theoretical approach might speed up your program by orders of magnitude. Use library functions. The routines in NumPy, SciPy,