FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpython/Tools/scripts/divmod_threshold.py at 3.15 · python/cpython · GitHub
python
cpython
Repository navigation
Code
Issues
5k+
(5k+)
Pull requests
2.3k
(2.3k)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpython
/
Tools
/
scripts
/
divmod_threshold.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
56 lines (46 loc) · 1.2 KB
Breadcrumbs
cpython
/
Tools
/
scripts
/
divmod_threshold.py
Copy path
File metadata and controls
56 lines (46 loc) · 1.2 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python3
#
# Determine threshold for switching from longobject.c divmod to
# _pylong.int_divmod().
from
random
import
randrange
from
time
import
perf_counter
as
now
from
_pylong
import
int_divmod
as
divmod_fast
BITS_PER_DIGIT
=
30
def
rand_digits
(
n
):
top
=
1
<<
(
n
*
BITS_PER_DIGIT
)
return
randrange
(
top
>>
1
,
top
)
def
probe_den
(
nd
):
den
=
rand_digits
(
nd
)
count
=
0
for
nn
in
range
(
nd
,
nd
+
3000
):
num
=
rand_digits
(
nn
)
t0
=
now
()
e1
,
e2
=
divmod
(
num
,
den
)
t1
=
now
()
f1
,
f2
=
divmod_fast
(
num
,
den
)
t2
=
now
()
s1
=
t1
-
t0
s2
=
t2
-
t1
assert
e1
==
f1
assert
e2
==
f2
if
s2
<
s1
:
count
+=
1
if
count
>=
3
:
print
(
"for"
,
nd
,
"denom digits,"
,
nn
-
nd
,
"extra num digits is enough"
,
)
break
else
:
count
=
0
else
:
print
(
"for"
,
nd
,
"denom digits, no num seems big enough"
)
def
main
():
for
nd
in
range
(
30
):
nd
=
(
nd
+
1
)
*
100
probe_den
(
nd
)
if
__name__
==
'__main__'
:
main
()
Back
|
FazBrowse Home
|
New Git URL