O'Reilly logo

Python Recipes Handbook: A Problem-Solution Approach by Joey Bernard

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

© Joey Bernard 2016

Joey Bernard, Python Recipes Handbook, 10.1007/978-1-4842-0241-8_14

14. Testing and Debugging

Joey Bernard

(1)Fredericton, New Brunswick, Canada

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

Problem

You want to time a section of code to see how long it takes to run.

Solution

The Python standard library includes a package named timeit that can run code multiple times and get average runtimes.

How It Works ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required