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
7b9bcb84
Commit
7b9bcb84
authored
Jul 15, 2010
by
Brett Cannon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Touch up comments and code along with outputting what the unit of measure is.
parent
0736767f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
7 deletions
+10
-7
Lib/importlib/test/benchmark.py
Lib/importlib/test/benchmark.py
+10
-7
No files found.
Lib/importlib/test/benchmark.py
View file @
7b9bcb84
"""Benchmark some basic import use-cases."""
# XXX
# - Bench from source (turn off bytecode generation)
# - Bench from bytecode (remove existence of source)
# - Bench bytecode generation
# - Bench extensions
# - from source
# + sys.dont_write_bytecode = True
# + sys.dont_write_bytecode = False
# - from bytecode
# - extensions
from
.
import
util
from
.source
import
util
as
source_util
import
imp
...
...
@@ -30,7 +31,7 @@ def bench(name, cleanup=lambda: None, *, seconds=1, repeat=3):
# One execution too far
if
total_time
>
seconds
:
count
-=
1
yield
count
yield
count
//
seconds
def
from_cache
(
repeat
):
"""sys.modules"""
...
...
@@ -49,13 +50,15 @@ def builtin_mod(repeat):
name
=
'errno'
if
name
in
sys
.
modules
:
del
sys
.
modules
[
name
]
# Relying on built-in importer being implicit.
for
result
in
bench
(
name
,
lambda
:
sys
.
modules
.
pop
(
name
),
repeat
=
repeat
):
yield
result
def
main
(
import_
,
repeat
=
3
):
def
main
(
import_
,
*
,
repeat
=
3
):
__builtins__
.
__import__
=
import_
benchmarks
=
from_cache
,
builtin_mod
print
(
"Measuring imports/second
\
n
"
)
for
benchmark
in
benchmarks
:
print
(
benchmark
.
__doc__
,
"["
,
end
=
' '
)
sys
.
stdout
.
flush
()
...
...
@@ -75,7 +78,7 @@ if __name__ == '__main__':
default
=
False
,
help
=
"use the built-in __import__"
)
options
,
args
=
parser
.
parse_args
()
if
args
:
raise
RuntimeError
(
"unrecognized args: {
0
}"
.
format
(
args
))
raise
RuntimeError
(
"unrecognized args: {}"
.
format
(
args
))
import_
=
__import__
if
not
options
.
builtin
:
import_
=
importlib
.
__import__
...
...
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