SF patch #868736: Disable GC for timeit
Make timings more consistent by temporarily disabling GC.
This commit is contained in:
parent
4cd5a08d8b
commit
816ed1b0bd
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue