diff options
author | Guido van Rossum <guido@python.org> | 1998-05-26 15:05:12 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1998-05-26 15:05:12 (GMT) |
commit | 16653cb27327288deb2068223501bf706cc65d46 (patch) | |
tree | 936508addd7740e43cc4a4f01378174e656163bb /Lib/test | |
parent | 7462942b69cf28533d175f1d8022924d616c58e8 (diff) | |
download | cpython-16653cb27327288deb2068223501bf706cc65d46.zip cpython-16653cb27327288deb2068223501bf706cc65d46.tar.gz cpython-16653cb27327288deb2068223501bf706cc65d46.tar.bz2 |
Add Tim's worst case scenario.
Revert to using whrandom so it will work with older versions of Python.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/sortperf.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/Lib/test/sortperf.py b/Lib/test/sortperf.py index 58fd8a7..34ed338 100644 --- a/Lib/test/sortperf.py +++ b/Lib/test/sortperf.py @@ -7,7 +7,7 @@ See tabulate() for output format. import sys import time -import random +import whrandom import marshal import tempfile import operator @@ -23,7 +23,7 @@ def randrange(n): except IOError: result = [] for i in range(n): - result.append(random.random()) + result.append(whrandom.random()) try: try: fp = open(fn, "wb") @@ -44,7 +44,7 @@ def randrange(n): ##assert len(result) == n # Shuffle it a bit... for i in range(10): - i = random.randint(0, n-1) + i = whrandom.randint(0, n-1) temp = result[:i] del result[:i] temp.reverse() @@ -75,10 +75,12 @@ def tabulate(r): /sort: ascending data ~sort: many duplicates -sort: all equal + !sort: worst case scenario """ - fmt = ("%2s %6s" + " %6s"*5) - print fmt % ("i", "2**i", "*sort", "\\sort", "/sort", "~sort", "-sort") + cases = ("*sort", "\\sort", "/sort", "~sort", "-sort", "!sort") + fmt = ("%2s %6s" + " %6s"*len(cases)) + print fmt % (("i", "2**i") + cases) for i in r: n = 1<<i L = randrange(n) @@ -97,6 +99,9 @@ def tabulate(r): del L L = map(abs, [-0.5]*n) doit(L) # -sort + L = range(n/2-1, -1, -1) + L[len(L):] = range(n/2) + doit(L) # !sort print def main(): @@ -129,7 +134,7 @@ def main(): y = (y^h^d) & 255 h = h>>8 z = (z^h^d) & 255 - random.seed(x, y, z) + whrandom.seed(x, y, z) r = range(k1, k2+1) # include the end point tabulate(r) |