SF patch #868736: Disable GC for timeit

Make timings more consistent by temporarily disabling GC.
This commit is contained in:
Raymond Hettinger 2004-01-04 03:47:51 +00:00
parent 4cd5a08d8b
commit 816ed1b0bd
1 changed files with 7 additions and 1 deletions

View File

@ -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.