This book has focused on giving you tips and tricks on how to write Python code. Very little space has been spent on making this code as good as it could be. In this chapter, you will look at techniques to analyze your code's performance. You will also look at ways to debug your program when errors and mistakes creep into the code you are writing.
14-1. Timing a Section of Code
You want to time a section of code to see how long it takes to run.
The Python standard library includes a package named timeit that can run code multiple times and get average runtimes.