]> granicus.if.org Git - python/commitdiff
Show how to re-enable GC during timings.
authorRaymond Hettinger <python@rcn.com>
Sun, 4 Jan 2004 21:19:18 +0000 (21:19 +0000)
committerRaymond Hettinger <python@rcn.com>
Sun, 4 Jan 2004 21:19:18 +0000 (21:19 +0000)
Doc/lib/libtimeit.tex

index 98c1c833ac6f13fb046b46509d18991bcd1d624a..1c4e05bafd4682c24e28276c9b787de32f441682 100644 (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}