[Python-checkins] r53109 - sandbox/trunk/import_in_py/importbench.py

brett.cannon python-checkins at python.org
Wed Dec 20 19:49:38 CET 2006


Author: brett.cannon
Date: Wed Dec 20 19:49:37 2006
New Revision: 53109

Modified:
   sandbox/trunk/import_in_py/importbench.py
Log:
Add a benchmark for importing a module in a package.


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 19:49:37 2006
@@ -234,6 +234,18 @@
         timer = import_and_clear_timer(pkg_details.pkg_name)
         return timer.repeat(repetitions, iterations)
         
+ at save_import_state
+def bench_module_in_package(repetitions, iterations):
+    """Benchmark importing a module that is contained within a package."""
+    sys.path = []
+    sys.meta_path = []
+    with PyPycPackage() as pkg_details:
+        # Import the package first to prime sys.modules.
+        __import__(pkg_details.pkg_name, {}, {}, [], 0)
+        # Shouldn't have to worry about attribute pre-existing on the package
+        # for the module.  It should get reset by the import.
+        timer = import_and_clear_timer(pkg_details.full_module_name)
+        return timer.repeat(repetitions, iterations)
 
 
 def display_results(fxn, name, spacing, repetitions, iterations):


More information about the Python-checkins mailing list