diff options
author | Tim Peters <tim.peters@gmail.com> | 2002-07-20 04:21:51 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2002-07-20 04:21:51 (GMT) |
commit | 0a30e648e06be85b3380a62ae156a9c7f343392f (patch) | |
tree | daa8de92db6f96adb92612f901ced5bd23a8e91a /Lib | |
parent | 1cfcafceb6b58dd912a2d15fc9b6002ef8a7b551 (diff) | |
download | cpython-0a30e648e06be85b3380a62ae156a9c7f343392f.zip cpython-0a30e648e06be85b3380a62ae156a9c7f343392f.tar.gz cpython-0a30e648e06be85b3380a62ae156a9c7f343392f.tar.bz2 |
Added new test "3sort". This is sorted data but with 3 random exchanges.
It's a little better than average for our sort.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/sortperf.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/Lib/test/sortperf.py b/Lib/test/sortperf.py index 546afd5..cd6bbcb 100644 --- a/Lib/test/sortperf.py +++ b/Lib/test/sortperf.py @@ -74,12 +74,13 @@ def tabulate(r): *sort: random data \sort: descending data /sort: ascending data + 3sort: ascending data but with 3 random exchanges ~sort: many duplicates =sort: all equal !sort: worst case scenario """ - cases = ("*sort", "\\sort", "/sort", "~sort", "=sort", "!sort") + cases = ("*sort", "\\sort", "/sort", "3sort", "~sort", "=sort", "!sort") fmt = ("%2s %7s" + " %6s"*len(cases)) print fmt % (("i", "2**i") + cases) for i in r: @@ -92,6 +93,13 @@ def tabulate(r): doit(L) # \sort doit(L) # /sort + # Do 3 random exchanges. + for dummy in range(3): + i1 = random.randrange(n) + i2 = random.randrange(n) + L[i1], L[i2] = L[i2], L[i1] + doit(L) # 3sort + # Arrange for lots of duplicates. if n > 4: del L[4:] |