1
- """Sort performance test."""
1
+ """Sort performance test.
2
+
3
+ See main() for command line syntax.
4
+ See tabulate() for output format.
5
+
6
+ """
2
7
3
8
import sys
4
9
import time
@@ -58,6 +63,20 @@ def doit(L):
58
63
f
10000
l ()
59
64
60
65
def tabulate (r ):
66
+ """Tabulate sort speed for lists of various sizes.
67
+
68
+ The sizes are 2**i for i in r (the argument, a list).
69
+
70
+ The output displays i, 2**i, and the time to sort arrays of 2**i
71
+ floating point numbers with the following properties:
72
+
73
+ *sort: random data
74
+ \sort: descending data
75
+ /sort: ascending data
76
+ ~sort: many duplicates
77
+ -sort: all equal
78
+
79
+ """
61
80
fmt = ("%2s %6s" + " %6s" * 5 )
62
81
print fmt % ("i" , "2**i" , "*sort" , "\\ sort" , "/sort" , "~sort" , "-sort" )
63
82
for i in r :
@@ -78,16 +97,22 @@ def tabulate(r):
78
97
print
79
98
80
99
def main ():
100
+ """Main program when invoked as a script.
101
+
102
+ One argument: tabulate a single row.
103
+ Two arguments: tabulate a range (inclusive).
104
+ Extra arguments are used to seed the random generator.
105
+
106
+ """
81
107
import string
82
108
# default range (inclusive)
83
109
k1 = 15
84
110
k2 = 19
85
- # one argument: single point
86
- # two arguments: specify range
87
111
if sys .argv [1 :]:
88
- k1 = string . atoi ( sys . argv [ 1 ])
89
- k2 = k1
112
+ # one argument: single point
113
+ k1 = k2 = string . atoi ( sys . argv [ 1 ])
90
114
if sys .argv [2 :]:
115
+ # two arguments: specify range
91
116
k2 = string .atoi (sys .argv [2 ])
92
117
if sys .argv [3 :]:
93
118
# derive random seed from remaining arguments
@@ -102,7 +127,7 @@ def main():
102
127
h = h >> 8
103
128
z = (z ^ h ^ d ) & 255
104
129
whrandom .seed (x , y , z )
105
- r = range (k1 , k2 + 1 )
130
+ r = range (k1 , k2 + 1 ) # include the end point
106
131
tabulate (r )
107
132
108
133
if __name__ == '__main__' :
0 commit comments