From the course: Faster Python Code
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Measuring time
- [Instructor] One of the simplest things we can do, is to measure time. Measuring time is helpful in many scenarios. When deciding between two alternatives, when gauging improvement, and to get metrics on run time, just to name a few. In Python, we have two basic methods of measuring time. The time module and the timeit module. Time is surprisingly tricky in computers. For example, if your computer updates its clock from the network while measuring, you might get negative results. I encourage you to read the awesome Falsehoods Programmers Believe About Time article to learn many more surprising aspects of how computers handle time. When measuring elapsed time, times when your process was sleeping due to rescheduling by the operating system are also included. You need to decide if you're interested in measuring sleeping time or not. In Python, people usually use the time function to measure time. However, in…