8000 Add a few doc strings. · python/cpython@03e35c5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 03e35c5

Browse files
committed
Add a few doc strings.
1 parent ea176b6 commit 03e35c5

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

Lib/test/sortperf.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
"""Sort performance test."""
1+
"""Sort performance test.
2+
3+
See main() for command line syntax.
4+
See tabulate() for output format.
5+
6+
"""
27

38
import sys
49
import time
@@ -58,6 +63,20 @@ def doit(L):
5863
f 10000 l()
5964

6065
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+
"""
6180
fmt = ("%2s %6s" + " %6s"*5)
6281
print fmt % ("i", "2**i", "*sort", "\\sort", "/sort", "~sort", "-sort")
6382
for i in r:
@@ -78,16 +97,22 @@ def tabulate(r):
7897
print
7998

8099
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+
"""
81107
import string
82108
# default range (inclusive)
83109
k1 = 15
84110
k2 = 19
85-
# one argument: single point
86-
# two arguments: specify range
87111
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])
90114
if sys.argv[2:]:
115+
# two arguments: specify range
91116
k2 = string.atoi(sys.argv[2])
92117
if sys.argv[3:]:
93118
# derive random seed from remaining arguments
@@ -102,7 +127,7 @@ def main():
102127
h = h>>8
103128
z = (z^h^d) & 255
104129
whrandom.seed(x, y, z)
105-
r = range(k1, k2+1)
130+
r = range(k1, k2+1) # include the end point
106131
tabulate(r)
107132

108133
if __name__ == '__main__':

0 commit comments

Comments
 (0)
0