[issue13351] Strange time complexity when creating nested lists

2011-11-05 Thread Jonas LM
Jonas LM added the comment: Confirmed that this was caused by the garbage collector, as pitrou suspected. Thanks! -- resolution: -> works for me status: open -> closed ___ Python tracker

[issue13351] Strange time complexity when creating nested lists

2011-11-05 Thread Antoine Pitrou
Antoine Pitrou added the comment: It's because of the cyclic garbage collector. If you call gc.disable() at the beginning of your benchmark, you'll see that runtimes get more similar in both cases. You can also use tuples instead of lists as much as possible, it will reduce pressure on the GC

[issue13351] Strange time complexity when creating nested lists

2011-11-05 Thread R. David Murray
R. David Murray added the comment: In the case of 'lists' an object is being allocated each time through the inner loop. In the case of simple_lists, no such allocation is being done. Your timing issues are probably related to the memory allocation behavior of your system. -- nosy:

[issue13351] Strange time complexity when creating nested lists

2011-11-05 Thread Jonas LM
New submission from Jonas LM : Consider the following snippets: def lists(n): start_time = time.time() lists = [None]*n for i in xrange(n): lists[i] = [None]*n for j in xrange(n): lists[i][j] = [] print time.time() - start_time def sim