Anonymous user
Compare sorting algorithms' performance: Difference between revisions
Compare sorting algorithms' performance (view source)
Revision as of 19:07, 24 December 2007
, 16 years ago→Plot timings: import numpy
m (→Examples of sorting routines: import random) |
m (→Plot timings: import numpy) |
||
Line 81:
<code>
import operator
import numpy, pylab
def plotdd(dictplotdict):
"""See ``plot_timings()`` below."""
symbols = ('o', '^', 'v', '<', '>', 's', '+', 'x', 'D', 'd',
'1', '2', '3', '4', 'h', 'H', 'p', '|', '_')
colors = map(None, 'bgrcmyk') # split string on distinct characters
for npoints, plotdict in dictplotdict.iteritems():
for ttle, lst in plotdict.iteritems():
pylab.hold(False)
for i, (label, polynom, x, y) in enumerate(sorted(lst,key=operator.itemgetter(0))):
pylab.plot(x, y, colors[i % len(colors)] + symbols[i % len(symbols)], label='%s %s' % (polynom, label))
pylab.hold(True)
y = numpy.polyval(polynom, x)
Line 139 ⟶ 138:
plotdd(ds) # see ``plotdd()`` above
</code>
===Figures: log2( time in microseconds ) vs. log2( sequence length )===
1 <= N <= 2**10 # an input sequence length
|