Timing the Functions
Profiling a program means measuring how long it takes to run and how much memory it uses. These two measures—time and space—are fundamental to the theoretical study of algorithms. They are also pretty important from a pragmatic point of view. Fast programs are more useful than slow ones, and programs that need more memory than what your computer has aren’t particularly useful at all.
This section introduces one way to time how long code takes to run. You’ll see how to run the three functions we developed to find the two lowest values in a list on 1,400 monthly readings of air pressure in Darwin, Australia, from 1882 to 1998.[6]
Module time contains functions related to time. One of these functions is perf_counter, which ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access