Compare sorting algorithms' performance: Difference between revisions

m
→‎Write timings: - removed comment
m (→‎Write timings: - removed comment)
Line 65:
===Write timings===
<code>
def write_timings(npoints=10, maxN=10**4, sort_functions=(builtinsort,insertion_sort, qsort), sequence_creators = (ones, range, shuffledrange)):
"""`npoints' and `maxN' are recomendations that may be ignored by implementation"""
Ns = range(2, maxN, maxN//npoints)
for sort in sort_functions:
for make_seq in sequence_creators:
Ts = map(lambda n: usec(sort, (make_seq(n),)), Ns)
writedat('%s-%s-%d-%d.xy' % (sort.__name__, make_seq.__name__, len(Ns), max(Ns)), Ns, Ts)
Ns, Ts)
</code>
Where ''writedat()'' is defined in the [[Write float arrays to a text file]], ''usec()'' - [[Query Performance]], ''insertion_sort()'' - [[Insertion sort]], ''qsort'' - [[Quicksort]] subtasks, correspondingly.
 
===Plot timings===
{{library|matplotlib}}
Anonymous user