summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-01-04 03:47:51 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-01-04 03:47:51 (GMT)
commit816ed1b0bdd3f50375bef334a41e5f20d58910f9 (patch)
tree6ce66369c4476f41296528afa0a55a13d246f01e
parent4cd5a08d8b120fa809cb4a5704cb34aa244263b5 (diff)
downloadcpython-816ed1b0bdd3f50375bef334a41e5f20d58910f9.zip
cpython-816ed1b0bdd3f50375bef334a41e5f20d58910f9.tar.gz
cpython-816ed1b0bdd3f50375bef334a41e5f20d58910f9.tar.bz2
SF patch #868736: Disable GC for timeit
Make timings more consistent by temporarily disabling GC.
-rw-r--r--Lib/timeit.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/Lib/timeit.py b/Lib/timeit.py
index 7829395..8c0f7a5 100644
--- a/Lib/timeit.py
+++ b/Lib/timeit.py
@@ -51,6 +51,7 @@ use python -O for the older versions to avoid timing SET_LINENO
instructions.
"""
+import gc
import sys
import time
try:
@@ -155,7 +156,12 @@ class Timer:
it = itertools.repeat(None, number)
else:
it = [None] * number
- return self.inner(it, self.timer)
+ gcold = gc.isenabled()
+ gc.disable()
+ timing = self.inner(it, self.timer)
+ if gcold:
+ gc.enable()
+ return timing
def repeat(self, repeat=default_repeat, number=default_number):
"""Call timeit() a few times.