[Python-checkins] r53091 - sandbox/trunk/import_in_py/importbench.py
brett.cannon
python-checkins at python.org
Wed Dec 20 02:18:47 CET 2006
Author: brett.cannon
Date: Wed Dec 20 02:18:46 2006
New Revision: 53091
Modified:
sandbox/trunk/import_in_py/importbench.py
Log:
Change argument order for repetitions and iterations so that it matches
timeit.Timer.repeat .
Modified: sandbox/trunk/import_in_py/importbench.py
==============================================================================
--- sandbox/trunk/import_in_py/importbench.py (original)
+++ sandbox/trunk/import_in_py/importbench.py Wed Dec 20 02:18:46 2006
@@ -18,7 +18,6 @@
its own benchmark.
"""
-#XXX make sure all code goes repetitions, iterations (and probably with those names).
from py_compile import compile as compile_to_pyc
import os
import StringIO
@@ -91,7 +90,7 @@
@save_import_state
-def bench_sys_modules(times, repeat):
+def bench_sys_modules(repetitions, iterations):
"""Benchmark returning a module from sys.modules."""
sys.path = []
sys.meta_path = []
@@ -100,10 +99,10 @@
# Force the module into sys.modules .
__import__(file_state.module_name, {})
timer = Timer("__import__(%r, {}, {}, [], 0)" % file_state.module_name)
- return timer.repeat(repeat, times)
+ return timer.repeat(repetitions, iterations)
@save_import_state
-def bench_nonexistent_module(times, repeat):
+def bench_nonexistent_module(repetitions, iterations):
"""How expensive is an import failure (with a single entry on sys.path)?"""
# Verify that the module does not exist.
sys.path = []
@@ -120,16 +119,16 @@
raise Exception("supposed non-existent module actually exists")
timer = Timer("try:__import__(%r, {}, {}, [], 0)\nexcept ImportError:pass" %
bad_name)
- return timer.repeat(repeat, times)
+ return timer.repeat(repetitions, iterations)
def py_pyc_module_benchmark(py, pyc):
@save_import_state
- def inner(times, repeat):
+ def inner(repetitions, iterations):
sys.path = []
sys.meta_path = []
with PyPycFiles(py, pyc) as file_state:
timer = import_and_clear_timer(file_state.module_name)
- return timer.repeat(repeat, times)
+ return timer.repeat(repetitions, iterations)
return inner
bench_pyc_with_py = py_pyc_module_benchmark(py=True, pyc=True)
@@ -137,15 +136,15 @@
bench_py_without_pyc = py_pyc_module_benchmark(py=True, pyc=False)
@save_import_state
-def bench_builtins(times, repeat):
+def bench_builtins(repetitions, iterations):
"""Benchmark the importation of a built-in module."""
sys.meta_path = []
sys.path = []
timer = import_and_clear_timer('xxsubtype')
- return timer.repeat(repeat, times)
+ return timer.repeat(repetitions, iterations)
@save_import_state
-def bench_frozen(times, repeat):
+def bench_frozen(repetitions, iterations):
"""Benchmark the importing of frozen modules."""
sys.path = []
sys.meta_path = []
@@ -153,12 +152,12 @@
sys.stdout = StringIO.StringIO()
try:
timer = import_and_clear_timer('__hello__')
- return timer.repeat(repeat, times)
+ return timer.repeat(repetitions, iterations)
finally:
sys.stdout = sys.__stdout__
@save_import_state
-def bench_extension(times, repeat):
+def bench_extension(repetitions, iterations):
"""Benchmark the importing of an extension module."""
# Choose an extension module that is always included with Python.
module = 'datetime'
@@ -168,11 +167,11 @@
sys.meta_path = []
sys.path = [directory]
timer = import_and_clear_timer(module)
- return timer.repeat(repeat, times)
+ return timer.repeat(repetitions, iterations)
-def display_results(fxn, name, spacing, repeat, times):
- timings = fxn(times, repeat)
+def display_results(fxn, name, spacing, repetitions, iterations):
+ timings = fxn(repetitions, iterations)
print "%s %s" % (name.ljust(spacing),
[int(result*1000) for result in timings])
More information about the Python-checkins
mailing list