mirror of
https://github.com/python/cpython.git
synced 2025-11-02 19:12:55 +00:00
Touch up comments and code along with outputting what the unit of measure is.
This commit is contained in:
parent
0736767fdf
commit
7b9bcb8411
1 changed files with 10 additions and 7 deletions
|
|
@ -1,9 +1,10 @@
|
||||||
"""Benchmark some basic import use-cases."""
|
"""Benchmark some basic import use-cases."""
|
||||||
# XXX
|
# XXX
|
||||||
# - Bench from source (turn off bytecode generation)
|
# - from source
|
||||||
# - Bench from bytecode (remove existence of source)
|
# + sys.dont_write_bytecode = True
|
||||||
# - Bench bytecode generation
|
# + sys.dont_write_bytecode = False
|
||||||
# - Bench extensions
|
# - from bytecode
|
||||||
|
# - extensions
|
||||||
from . import util
|
from . import util
|
||||||
from .source import util as source_util
|
from .source import util as source_util
|
||||||
import imp
|
import imp
|
||||||
|
|
@ -30,7 +31,7 @@ def bench(name, cleanup=lambda: None, *, seconds=1, repeat=3):
|
||||||
# One execution too far
|
# One execution too far
|
||||||
if total_time > seconds:
|
if total_time > seconds:
|
||||||
count -= 1
|
count -= 1
|
||||||
yield count
|
yield count // seconds
|
||||||
|
|
||||||
def from_cache(repeat):
|
def from_cache(repeat):
|
||||||
"""sys.modules"""
|
"""sys.modules"""
|
||||||
|
|
@ -49,13 +50,15 @@ def builtin_mod(repeat):
|
||||||
name = 'errno'
|
name = 'errno'
|
||||||
if name in sys.modules:
|
if name in sys.modules:
|
||||||
del sys.modules[name]
|
del sys.modules[name]
|
||||||
|
# Relying on built-in importer being implicit.
|
||||||
for result in bench(name, lambda: sys.modules.pop(name), repeat=repeat):
|
for result in bench(name, lambda: sys.modules.pop(name), repeat=repeat):
|
||||||
yield result
|
yield result
|
||||||
|
|
||||||
|
|
||||||
def main(import_, repeat=3):
|
def main(import_, *, repeat=3):
|
||||||
__builtins__.__import__ = import_
|
__builtins__.__import__ = import_
|
||||||
benchmarks = from_cache, builtin_mod
|
benchmarks = from_cache, builtin_mod
|
||||||
|
print("Measuring imports/second\n")
|
||||||
for benchmark in benchmarks:
|
for benchmark in benchmarks:
|
||||||
print(benchmark.__doc__, "[", end=' ')
|
print(benchmark.__doc__, "[", end=' ')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
@ -75,7 +78,7 @@ if __name__ == '__main__':
|
||||||
default=False, help="use the built-in __import__")
|
default=False, help="use the built-in __import__")
|
||||||
options, args = parser.parse_args()
|
options, args = parser.parse_args()
|
||||||
if args:
|
if args:
|
||||||
raise RuntimeError("unrecognized args: {0}".format(args))
|
raise RuntimeError("unrecognized args: {}".format(args))
|
||||||
import_ = __import__
|
import_ = __import__
|
||||||
if not options.builtin:
|
if not options.builtin:
|
||||||
import_ = importlib.__import__
|
import_ = importlib.__import__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue