[Python-checkins] benchmarks: Fallback to a non-accelerated version of etree if the accelerated

brett.cannon python-checkins at python.org
Fri Oct 16 13:39:20 EDT 2015


https://hg.python.org/benchmarks/rev/934dffe6b0bd
changeset: 226:934dffe6b0bd
user: Brett Cannon <brett at python.org>
date: Fri Oct 16 10:39:14 2015 -0700
summary:
 Fallback to a non-accelerated version of etree if the accelerated
version is unavailable.
This is for IronPython which has no cElementTree module but does have
ElementTree.
files:
 performance/bm_elementtree.py | 12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/performance/bm_elementtree.py b/performance/bm_elementtree.py
--- a/performance/bm_elementtree.py
+++ b/performance/bm_elementtree.py
@@ -12,6 +12,7 @@
 __author__ = "stefan_ml at behnel.de (Stefan Behnel)"
 
 default_etmodule = "xml.etree.cElementTree"
+fallback_etmodule = 'xml.etree.ElementTree'
 
 # Python imports
 import optparse
@@ -247,8 +248,15 @@
 from importlib import import_module
 except ImportError:
 def import_module(module_name):
- return __import__(module_name, fromlist=['*'])
+ __import__(module_name)
+ return sys.modules[module_name]
 
- etree_module = import_module(options.etree_module)
+ try:
+ etree_module = import_module(options.etree_module)
+ except ImportError:
+ if options.etree_module != default_etmodule:
+ raise
+ etree_module = import_module(fallback_etmodule)
+
 util.run_benchmark(options, options.num_runs,
 run_etree_benchmark, etree_module, bench_func)
-- 
Repository URL: https://hg.python.org/benchmarks


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /