Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
16653cb2
Commit
16653cb2
authored
May 26, 1998
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Tim's worst case scenario.
Revert to using whrandom so it will work with older versions of Python.
parent
7462942b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
6 deletions
+11
-6
Lib/test/sortperf.py
Lib/test/sortperf.py
+11
-6
No files found.
Lib/test/sortperf.py
View file @
16653cb2
...
...
@@ -7,7 +7,7 @@ See tabulate() for output format.
import
sys
import
time
import
random
import
wh
random
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
(
wh
random
.
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
=
wh
random
.
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
)
wh
random
.
seed
(
x
,
y
,
z
)
r
=
range
(
k1
,
k2
+
1
)
# include the end point
tabulate
(
r
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment