GC performance with lists

jonas at mit.edu jonas at mit.edu
Tue Sep 4 10:06:59 EDT 2007


While working on some python wrapping, I've run into some problems
where the GC seems to take an unreasonable amount of time to run. The
code below is a demonstration:

import gc
#gc.disable()

data = []
for i in xrange(100000):

    shortdata = []
    for j in range(57):
        mytuple = (j, i+1, i+2, i+3, i+4, i+5, i+6)
        shortdata.append(mytuple)
    data.extend(shortdata)

print len(data)

with gc disabled (the second line) the code runs in 15 seconds, with
it enabled it runs in 2:15, or ~9x slower. I expected some gc
overhead, but not an order of magnitude! Am I doing something
obviously wrong in the above code?

Thanks,
     ...Eric




More information about the Python-list mailing list