Show how to re-enable GC during timings.

This commit is contained in:
Raymond Hettinger 2004-01-04 21:19:18 +00:00
parent 2b2c97356f
commit c14149e6ef
1 changed files with 12 additions and 0 deletions

View File

@ -82,6 +82,18 @@ times, measured in seconds as a float. The argument is the number of
times through the loop, defaulting to one million. The main
statement, the setup statement and the timer function to be used are
passed to the constructor.
\begin{notice}
By default, \method{timeit()} temporarily turns off garbage collection
during the timing. The advantage of this approach is that it makes
independent timings more comparable. This disadvantage is that GC
may be an important component of the performance of the function being
measured. If so, GC can be re-enabled as the first statement in the
\var{setup} string. For example:
\begin{verbatim}
timeit.Timer('for i in xrange(10): oct(i)', 'gc.enable()').timeit()
\end{verbatim}
\end{notice}
\end{methoddesc}