[Python-checkins] cpython: Have importlib.test.benchmark test with tabnanny as a medium-sized test.

brett.cannon python-checkins at python.org
Tue Feb 7 15:20:39 CET 2012


http://hg.python.org/cpython/rev/7d4525a96cf2
changeset:   74816:7d4525a96cf2
parent:      74809:567767a6df02
user:        Brett Cannon <brett at python.org>
date:        Tue Feb 07 09:19:12 2012 -0500
summary:
  Have importlib.test.benchmark test with tabnanny as a medium-sized test.

files:
  Lib/importlib/test/benchmark.py |  90 +++++++++++++-------
  1 files changed, 58 insertions(+), 32 deletions(-)


diff --git a/Lib/importlib/test/benchmark.py b/Lib/importlib/test/benchmark.py
--- a/Lib/importlib/test/benchmark.py
+++ b/Lib/importlib/test/benchmark.py
@@ -13,6 +13,7 @@
 import os
 import py_compile
 import sys
+import tabnanny
 import timeit
 
 
@@ -60,7 +61,7 @@
 
 
 def source_wo_bytecode(seconds, repeat):
-    """Source w/o bytecode: simple"""
+    """Source w/o bytecode: small"""
     sys.dont_write_bytecode = True
     try:
         name = '__importlib_test_benchmark__'
@@ -74,23 +75,30 @@
         sys.dont_write_bytecode = False
 
 
-def decimal_wo_bytecode(seconds, repeat):
-    """Source w/o bytecode: decimal"""
-    name = 'decimal'
-    decimal_bytecode = imp.cache_from_source(decimal.__file__)
-    if os.path.exists(decimal_bytecode):
-        os.unlink(decimal_bytecode)
-    sys.dont_write_bytecode = True
-    try:
-        for result in bench(name, lambda: sys.modules.pop(name), repeat=repeat,
-                            seconds=seconds):
-            yield result
-    finally:
-        sys.dont_write_bytecode = False
+def _wo_bytecode(module):
+    name = module.__name__
+    def benchmark_wo_bytecode(seconds, repeat):
+        """Source w/o bytecode: {}"""
+        bytecode_path = imp.cache_from_source(module.__file__)
+        if os.path.exists(bytecode_path):
+            os.unlink(bytecode_path)
+        sys.dont_write_bytecode = True
+        try:
+            for result in bench(name, lambda: sys.modules.pop(name),
+                                repeat=repeat, seconds=seconds):
+                yield result
+        finally:
+            sys.dont_write_bytecode = False
+
+    benchmark_wo_bytecode.__doc__ = benchmark_wo_bytecode.__doc__.format(name)
+    return benchmark_wo_bytecode
+
+tabnanny_wo_bytecode = _wo_bytecode(tabnanny)
+decimal_wo_bytecode = _wo_bytecode(decimal)
 
 
 def source_writing_bytecode(seconds, repeat):
-    """Source writing bytecode: simple"""
+    """Source writing bytecode: small"""
     assert not sys.dont_write_bytecode
     name = '__importlib_test_benchmark__'
     with source_util.create_modules(name) as mapping:
@@ -102,19 +110,27 @@
             yield result
 
 
-def decimal_writing_bytecode(seconds, repeat):
-    """Source writing bytecode: decimal"""
-    assert not sys.dont_write_bytecode
-    name = 'decimal'
-    def cleanup():
-        sys.modules.pop(name)
-        os.unlink(imp.cache_from_source(decimal.__file__))
-    for result in bench(name, cleanup, repeat=repeat, seconds=seconds):
-        yield result
+def _writing_bytecode(module):
+    name = module.__name__
+    def writing_bytecode_benchmark(seconds, repeat):
+        """Source writing bytecode: {}"""
+        assert not sys.dont_write_bytecode
+        def cleanup():
+            sys.modules.pop(name)
+            os.unlink(imp.cache_from_source(module.__file__))
+        for result in bench(name, cleanup, repeat=repeat, seconds=seconds):
+            yield result
+
+    writing_bytecode_benchmark.__doc__ = (
+                                writing_bytecode_benchmark.__doc__.format(name))
+    return writing_bytecode_benchmark
+
+tabnanny_writing_bytecode = _writing_bytecode(tabnanny)
+decimal_writing_bytecode = _writing_bytecode(decimal)
 
 
 def source_using_bytecode(seconds, repeat):
-    """Bytecode w/ source: simple"""
+    """Source w/ bytecode: small"""
     name = '__importlib_test_benchmark__'
     with source_util.create_modules(name) as mapping:
         py_compile.compile(mapping[name])
@@ -124,13 +140,21 @@
             yield result
 
 
-def decimal_using_bytecode(seconds, repeat):
-    """Bytecode w/ source: decimal"""
-    name = 'decimal'
-    py_compile.compile(decimal.__file__)
-    for result in bench(name, lambda: sys.modules.pop(name), repeat=repeat,
-                        seconds=seconds):
-        yield result
+def _using_bytecode(module):
+    name = module.__name__
+    def using_bytecode_benchmark(seconds, repeat):
+        """Source w/ bytecode: {}"""
+        py_compile.compile(module.__file__)
+        for result in bench(name, lambda: sys.modules.pop(name), repeat=repeat,
+                            seconds=seconds):
+            yield result
+
+    using_bytecode_benchmark.__doc__ = (
+                                using_bytecode_benchmark.__doc__.format(name))
+    return using_bytecode_benchmark
+
+tabnanny_using_bytecode = _using_bytecode(tabnanny)
+decimal_using_bytecode = _using_bytecode(decimal)
 
 
 def main(import_, filename=None, benchmark=None):
@@ -143,6 +167,8 @@
     benchmarks = (from_cache, builtin_mod,
                   source_using_bytecode, source_wo_bytecode,
                   source_writing_bytecode,
+                  tabnanny_using_bytecode, tabnanny_wo_bytecode,
+                  tabnanny_writing_bytecode,
                   decimal_using_bytecode, decimal_writing_bytecode,
                   decimal_wo_bytecode,)
     if benchmark:

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list