import time import gc class A: def __init__(self): self.x = 1 self.y = 2 self.why = 'no reason' def time_to_append(size, append_list=[], item_gen=None): t0 = time.time() for i in xrange(0, size): if item_gen: append_list.append(item_gen()) else: append_list.append((1,2,3,4)) # append a tuple return time.time() - t0 def test(): x = [] print "with gc" count = 10000 for i in xrange(0,1000): print "for list length", len(x), time_to_append(count, x, lambda: A()), "seconds per", count def test_nogc(): x = [] print "without gc" count = 10000 for i in xrange(0,1000): gc.disable() print "for list length", len(x), time_to_append(count, x, lambda: A()), "seconds per", count gc.enable() if __name__ == '__main__': #test() test_nogc()