Commit 0cff594a authored by Tim Peters's avatar Tim Peters

New test %sort. This takes a sorted list, picks 1% of the list positions

at random, and replaces the elements at those positions with new random
values.  I was pleasantly surprised by how fast this goes!  It's hard to
conceive of an algorithm that could special-case for this effectively.
Plus it's exactly what happens if a burst of gamma rays corrupts your
sorted database on disk <wink>.

 i    2**i  *sort  ...  %sort
15   32768   0.18  ...   0.03
16   65536   0.24  ...   0.04
17  131072   0.53  ...   0.08
18  262144   1.17  ...   0.16
19  524288   2.56  ...   0.35
20 1048576   5.54  ...   0.77
parent 9243e35e
...@@ -76,12 +76,13 @@ def tabulate(r): ...@@ -76,12 +76,13 @@ def tabulate(r):
/sort: ascending data /sort: ascending data
3sort: ascending, then 3 random exchanges 3sort: ascending, then 3 random exchanges
+sort: ascending, then 10 random at the end +sort: ascending, then 10 random at the end
%sort: ascending, then randomly replace 1% of the elements w/ random values
~sort: many duplicates ~sort: many duplicates
=sort: all equal =sort: all equal
!sort: worst case scenario !sort: worst case scenario
""" """
cases = tuple([ch + "sort" for ch in r"*\/3+~=!"]) cases = tuple([ch + "sort" for ch in r"*\/3+%~=!"])
fmt = ("%2s %7s" + " %6s"*len(cases)) fmt = ("%2s %7s" + " %6s"*len(cases))
print fmt % (("i", "2**i") + cases) print fmt % (("i", "2**i") + cases)
for i in r: for i in r:
...@@ -106,6 +107,11 @@ def tabulate(r): ...@@ -106,6 +107,11 @@ def tabulate(r):
L[-10:] = [random.random() for dummy in range(10)] L[-10:] = [random.random() for dummy in range(10)]
doit(L) # +sort doit(L) # +sort
# Replace 1% of the elements at random.
for dummy in xrange(n // 100):
L[random.randrange(n)] = random.random()
doit(L) # %sort
# Arrange for lots of duplicates. # Arrange for lots of duplicates.
if n > 4: if n > 4:
del L[4:] del L[4:]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment