[Python-Dev] Optimizing list.sort() by checking type in advance

Terry Reedy tjreedy at udel.edu
Tue Oct 11 20:08:22 EDT 2016


On 10/11/2016 10:26 AM, Chris Angelico wrote:

> After the first call, the list will be sorted. Any subsequent attempts
> will use the sorted list.

This seems like a generic issue with timing mutation methods.  Is the 
mutated output suitable input for another mutation.  With list.reverse, 
the output is suitable.  Ditto for other permutations that are 
independent of the data, including random.shuffle.  With list.pop, the 
number of mutations has to be limited to the length of the list.  With 
list.sort, the list needs to be 'restored' -- either copied or shuffled 
each time.  So it seems that one is stuck with timing 'restore', restore 
+ sort_a, restore + sort_b, subtracting the timing for restore, and 
comparing.  But I am sure Tim worked this out in his test code, which 
should be reused, perhaps updated with Viktor's perf module to get the 
most stable timings possible.

-- 
Terry Jan Reedy



More information about the Python-Dev mailing list