mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
SF patch #868736: Disable GC for timeit
Make timings more consistent by temporarily disabling GC.
This commit is contained in:
parent
4cd5a08d8b
commit
816ed1b0bd
1 changed files with 7 additions and 1 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue