summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2013-04-06 12:53:08 +0200
committerStefan Behnel <stefan_ml@behnel.de>2013-04-06 12:53:08 +0200
commit18b21d5cb7ba6bb56d929fc5b9716d11b547354a (patch)
treee7904a4b8b01ff4ef3375fcbda511df5205b5a6f
parent00565de6e01863013f15998b4be0a464440e4fea (diff)
downloadpython-lxml-18b21d5cb7ba6bb56d929fc5b9716d11b547354a.tar.gz
fix XPath expressions in benchmark and add a new comparison
-rw-r--r--benchmark/bench_etree.py26
-rw-r--r--benchmark/bench_xpath.py8
2 files changed, 29 insertions, 5 deletions
diff --git a/benchmark/bench_etree.py b/benchmark/bench_etree.py
index 29846a8c..8d4eb4b2 100644
--- a/benchmark/bench_etree.py
+++ b/benchmark/bench_etree.py
@@ -408,7 +408,7 @@ class BenchMark(benchbase.TreeBenchMark):
if xpath is None:
ns, tag = self.SEARCH_TAG[1:].split('}')
xpath = self._bench_xpath_single_xpath = self.etree.XPath(
- './/p:%s' % tag, namespaces={'p': ns})
+ './/p:%s[1]' % tag, namespaces={'p': ns})
xpath(root)
@nochange
@@ -419,6 +419,30 @@ class BenchMark(benchbase.TreeBenchMark):
def bench_iter_single(self, root):
next(root.iter(self.SEARCH_TAG))
+ _bench_xpath_two_xpath = None
+
+ @nochange
+ @onlylib('lxe')
+ def bench_xpath_two(self, root):
+ xpath = self._bench_xpath_two_xpath
+ if xpath is None:
+ ns, tag = self.SEARCH_TAG[1:].split('}')
+ xpath = self._bench_xpath_two_xpath = self.etree.XPath(
+ './/p:%s[position() < 3]' % tag, namespaces={'p': ns})
+ xpath(root)
+
+ @nochange
+ def bench_iterfind_two(self, root):
+ it = root.iterfind(".//%s" % self.SEARCH_TAG)
+ next(it)
+ next(it)
+
+ @nochange
+ def bench_iter_two(self, root):
+ it = root.iter(self.SEARCH_TAG)
+ next(it)
+ next(it)
+
if __name__ == '__main__':
benchbase.main(BenchMark)
diff --git a/benchmark/bench_xpath.py b/benchmark/bench_xpath.py
index 997f946d..22d4e6ac 100644
--- a/benchmark/bench_xpath.py
+++ b/benchmark/bench_xpath.py
@@ -13,7 +13,7 @@ class XPathBenchMark(benchbase.TreeBenchMark):
@onlylib('lxe')
@children
def bench_xpath_class(self, children):
- xpath = self.etree.XPath("./*[0]")
+ xpath = self.etree.XPath("./*[1]")
for child in children:
xpath(child)
@@ -22,7 +22,7 @@ class XPathBenchMark(benchbase.TreeBenchMark):
@children
def bench_xpath_class_repeat(self, children):
for child in children:
- xpath = self.etree.XPath("./*[0]")
+ xpath = self.etree.XPath("./*[1]")
xpath(child)
@nochange
@@ -30,14 +30,14 @@ class XPathBenchMark(benchbase.TreeBenchMark):
def bench_xpath_element(self, root):
xpath = self.etree.XPathElementEvaluator(root)
for child in root:
- xpath.evaluate("./*[0]")
+ xpath.evaluate("./*[1]")
@nochange
@onlylib('lxe')
@children
def bench_xpath_method(self, children):
for child in children:
- child.xpath("./*[0]")
+ child.xpath("./*[1]")
@nochange
@onlylib('lxe')