From 16653cb27327288deb2068223501bf706cc65d46 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Tue, 26 May 1998 15:05:12 +0000 Subject: [PATCH] Add Tim's worst case scenario. Revert to using whrandom so it will work with older versions of Python. --- Lib/test/sortperf.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Lib/test/sortperf.py b/Lib/test/sortperf.py index 58fd8a70285..34ed3383273 100644 --- a/Lib/test/sortperf.py +++ b/Lib/test/sortperf.py @@ -7,7 +7,7 @@ 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<>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)