diff options
author | scoder <none@none> | 2007-03-16 20:26:13 +0100 |
---|---|---|
committer | scoder <none@none> | 2007-03-16 20:26:13 +0100 |
commit | 30c9b0357ef6345ae200f76513f931eb46c7a38b (patch) | |
tree | 8c8e3281a7fd701e12810395303c6e6faf7b497d /benchmark/bench_xpath.py | |
parent | 01e76044d30e1be0272b6afc728078bf2afa0773 (diff) | |
download | python-lxml-30c9b0357ef6345ae200f76513f931eb46c7a38b.tar.gz |
[svn r2199] benchmark both the old and the new way of using extension functions
--HG--
branch : trunk
Diffstat (limited to 'benchmark/bench_xpath.py')
-rw-r--r-- | benchmark/bench_xpath.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/benchmark/bench_xpath.py b/benchmark/bench_xpath.py index 8e971679..fc4c0419 100644 --- a/benchmark/bench_xpath.py +++ b/benchmark/bench_xpath.py @@ -34,7 +34,7 @@ class XPathBenchMark(benchbase.BenchMarkBase): child.xpath("./*[0]") @onlylib('lxe') - def bench_xpath_extensions_old(self, root): + def bench_xpath_old_extensions(self, root): def return_child(_, element): if element: return element[0] @@ -45,5 +45,21 @@ class XPathBenchMark(benchbase.BenchMarkBase): for child in root: xpath(child) + @onlylib('lxe') + def bench_xpath_extensions(self, root): + def return_child(_, element): + if element: + return element[0] + else: + return () + self.etree.FunctionNamespace("test")["t"] = return_child + + try: + xpath = self.etree.XPath("test:t(.)", {"test":"test"}) + for child in root: + xpath(child) + finally: + del self.etree.FunctionNamespace("test")["t"] + if __name__ == '__main__': benchbase.main(XPathBenchMark) |