Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0a30e64

Browse files
committed
Added new test "3sort". This is sorted data but with 3 random exchanges.
It's a little better than average for our sort.
1 parent 1cfcafc commit 0a30e64

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

Lib/test/sortperf.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,13 @@ def tabulate(r):
7474
*sort: random data
7575
\sort: descending data
7676
/sort: ascending data
77+
3sort: ascending data but with 3 random exchanges
7778
~sort: many duplicates
7879
=sort: all equal
7980
!sort: worst case scenario
8081
8182
"""
82-
cases = ("*sort", "\\sort", "/sort", "~sort", "=sort", "!sort")
83+
cases = ("*sort", "\\sort", "/sort", "3sort", "~sort", "=sort", "!sort")
8384
fmt = ("%2s %7s" + " %6s"*len(cases))
8485
print fmt % (("i", "2**i") + cases)
8586
for i in r:
@@ -92,6 +93,13 @@ def tabulate(r):
9293
doit(L) # \sort
9394
doit(L) # /sort
9495

96+
# Do 3 random exchanges.
97+
for dummy in range(3):
98+
i1 = random.randrange(n)
99+
i2 = random.randrange(n)
100+
L[i1], L[i2] = L[i2], L[i1]
101+
doit(L) # 3sort
102+
95103
# Arrange for lots of duplicates.
96104
if n > 4:
97105
del L[4:]

0 commit comments

Comments
 (0)