[Lxml-checkins] r42199 - lxml/trunk/benchmark
scoder at codespeak.net
scoder at codespeak.net
Fri Apr 20 12:42:01 CEST 2007
Author: scoder
Date: Fri Apr 20 12:42:01 2007
New Revision: 42199
Modified:
lxml/trunk/benchmark/bench_objectify.py
lxml/trunk/benchmark/bench_xpath.py
Log:
cleanup in benchmarks, use children where appropriate
Modified: lxml/trunk/benchmark/bench_objectify.py
==============================================================================
--- lxml/trunk/benchmark/bench_objectify.py (original)
+++ lxml/trunk/benchmark/bench_objectify.py Fri Apr 20 12:42:01 2007
@@ -10,6 +10,9 @@
############################################################
class BenchMark(benchbase.BenchMarkBase):
+ repeat1000 = range(1000)
+ repeat3000 = range(3000)
+
def __init__(self, lib):
from lxml import etree, objectify
self.objectify = objectify
@@ -20,37 +23,37 @@
def bench_attribute(self, root):
"1 2 4"
- for i in repeat(None, 3000):
+ for i in self.repeat3000:
root.zzzzz
def bench_attribute_cached(self, root):
"1 2 4"
cache = root.zzzzz
- for i in repeat(None, 3000):
+ for i in self.repeat3000:
root.zzzzz
def bench_attributes_deep(self, root):
"1 2 4"
- for i in repeat(None, 3000):
+ for i in self.repeat3000:
root.zzzzz['{cdefg}z00000']
def bench_attributes_deep_cached(self, root):
"1 2 4"
cache1 = root.zzzzz
cache2 = cache1['{cdefg}z00000']
- for i in repeat(None, 3000):
+ for i in self.repeat3000:
root.zzzzz['{cdefg}z00000']
def bench_objectpath(self, root):
"1 2 4"
path = self.objectify.ObjectPath(".zzzzz")
- for i in repeat(None, 3000):
+ for i in self.repeat3000:
path(root)
def bench_objectpath_deep(self, root):
"1 2 4"
path = self.objectify.ObjectPath(".zzzzz.{cdefg}z00000")
- for i in repeat(None, 3000):
+ for i in self.repeat3000:
path(root)
def bench_objectpath_deep_cached(self, root):
@@ -58,7 +61,7 @@
cache1 = root.zzzzz
cache2 = cache1['{cdefg}z00000']
path = self.objectify.ObjectPath(".zzzzz.{cdefg}z00000")
- for i in repeat(None, 3000):
+ for i in self.repeat3000:
path(root)
@with_text(text=True, utext=True, no_text=True)
@@ -72,7 +75,7 @@
def bench_type_inference(self, root):
"1 2 4"
el = root.aaaaa
- for i in repeat(None, 1000):
+ for i in self.repeat1000:
el.getchildren()
@with_text(text=True)
@@ -80,7 +83,7 @@
"1 2 4"
el = root.aaaaa
self.objectify.annotate(el)
- for i in repeat(None, 1000):
+ for i in self.repeat1000:
el.getchildren()
Modified: lxml/trunk/benchmark/bench_xpath.py
==============================================================================
--- lxml/trunk/benchmark/bench_xpath.py (original)
+++ lxml/trunk/benchmark/bench_xpath.py Fri Apr 20 12:42:01 2007
@@ -3,7 +3,7 @@
from StringIO import StringIO
import benchbase
-from benchbase import with_attributes, with_text, onlylib, serialized
+from benchbase import with_attributes, with_text, onlylib, serialized, children
############################################################
# Benchmarks
@@ -11,14 +11,16 @@
class XPathBenchMark(benchbase.BenchMarkBase):
@onlylib('lxe')
- def bench_xpath_class(self, root):
+ @children
+ def bench_xpath_class(self, children):
xpath = self.etree.XPath("./*[0]")
- for child in root:
+ for child in children:
xpath(child)
@onlylib('lxe')
- def bench_xpath_class_repeat(self, root):
- for child in root:
+ @children
+ def bench_xpath_class_repeat(self, children):
+ for child in children:
xpath = self.etree.XPath("./*[0]")
xpath(child)
@@ -29,12 +31,14 @@
xpath.evaluate("./*[0]")
@onlylib('lxe')
- def bench_xpath_method(self, root):
- for child in root:
+ @children
+ def bench_xpath_method(self, children):
+ for child in children:
child.xpath("./*[0]")
@onlylib('lxe')
- def bench_xpath_old_extensions(self, root):
+ @children
+ def bench_xpath_old_extensions(self, children):
def return_child(_, elements):
if elements:
return elements[0][0]
@@ -43,11 +47,12 @@
extensions = {("test", "child") : return_child}
xpath = self.etree.XPath("t:child(.)", namespaces={"test":"t"},
extensions=extensions)
- for child in root:
+ for child in children:
xpath(child)
@onlylib('lxe')
- def bench_xpath_extensions(self, root):
+ @children
+ def bench_xpath_extensions(self, children):
def return_child(_, elements):
if elements:
return elements[0][0]
@@ -57,7 +62,7 @@
try:
xpath = self.etree.XPath("test:t(.)", {"test":"testns"})
- for child in root:
+ for child in children:
xpath(child)
finally:
del self.etree.FunctionNamespace("testns")["t"]
More information about the lxml-checkins
mailing list