Project: Program Performance
Exercises 14.5 and 14.6 describe two of the improvements that can be made
to the efficiency of Listing 14.1. Because they reduce the numb er of loop
executions, they must make the program faster, but by how much? Is the
improvement significant? Measuring program performance is one way to
analyze the impact of changes made to your code.
In Python, we can get reasonably accurate timings using this function from
the time module:
clock() Current processor time.
The standard way to use a clock is to surround the code you want to measure
with two calls to the clock, like this:
start = time.clock()
sieve(10000)
stop = time.clock()
elapsed ...

Get A Concise Introduction to Programming in Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.