summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorscoder <none@none>2006-10-26 08:54:50 +0200
committerscoder <none@none>2006-10-26 08:54:50 +0200
commit6bdfa119a7453888cf99ea8745f26868c612dfbe (patch)
treeed84ee4f644a9004482d2532a2e0837eaec74161 /benchmark
parentac8a7312b43b30663444e4a4261115d7747d8641 (diff)
downloadpython-lxml-6bdfa119a7453888cf99ea8745f26868c612dfbe.tar.gz
[svn r1994] cleanup in benchmarks, new objectify benchmark class
--HG-- branch : trunk
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/bench_objectify.py60
-rw-r--r--benchmark/benchbase.py12
2 files changed, 66 insertions, 6 deletions
diff --git a/benchmark/bench_objectify.py b/benchmark/bench_objectify.py
new file mode 100644
index 00000000..672f86ad
--- /dev/null
+++ b/benchmark/bench_objectify.py
@@ -0,0 +1,60 @@
+import sys, copy
+from itertools import *
+from StringIO import StringIO
+
+from lxml import etree, objectify
+
+parser = etree.XMLParser(remove_blank_text=True)
+lookup = etree.ElementNamespaceClassLookup(objectify.ObjectifyElementClassLookup())
+parser.setElementClassLookup(lookup)
+
+import benchbase
+from benchbase import with_attributes, with_text, onlylib, serialized
+
+############################################################
+# Benchmarks
+############################################################
+
+class BenchMark(benchbase.BenchMarkBase):
+ def __init__(self, lib):
+ benchbase.BenchMarkBase.__init__(self, lib, parser)
+
+ def bench_attributes(self, root):
+ "1 2 4"
+ for i in repeat(None, 3000):
+ root.zzzzz
+
+ def bench_attributes_deep(self, root):
+ "1 2 4"
+ for i in repeat(None, 3000):
+ 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):
+ root.zzzzz['{cdefg}z00000']
+
+ def bench_objectpath(self, root):
+ "1 2 4"
+ path = objectify.ObjectPath(".zzzzz")
+ for i in repeat(None, 3000):
+ path(root)
+
+ def bench_objectpath_deep(self, root):
+ "1 2 4"
+ path = objectify.ObjectPath(".zzzzz.{cdefg}z00000")
+ for i in repeat(None, 3000):
+ path(root)
+
+ def bench_objectpath_deep_cached(self, root):
+ "1 2 4"
+ cache1 = root.zzzzz
+ cache2 = cache1['{cdefg}z00000']
+ path = objectify.ObjectPath(".zzzzz.{cdefg}z00000")
+ for i in repeat(None, 3000):
+ path(root)
+
+if __name__ == '__main__':
+ benchbase.main(BenchMark)
diff --git a/benchmark/benchbase.py b/benchmark/benchbase.py
index ccbdcee3..afaa71ee 100644
--- a/benchmark/benchbase.py
+++ b/benchmark/benchbase.py
@@ -96,7 +96,7 @@ class BenchMarkBase(object):
SEARCH_TAG = "{cdefg}a00001"
- def __init__(self, etree):
+ def __init__(self, etree, etree_parser=None):
self.etree = etree
libname = etree.__name__.split('.')[-1]
self.lib_name = self._LIB_NAME_MAP.get(libname, libname)
@@ -104,8 +104,8 @@ class BenchMarkBase(object):
if libname == 'etree':
deepcopy = copy.deepcopy
def set_property(root, fname):
- setattr(self, fname, lambda : deepcopy(root))
xml = self._serialize_tree(root)
+ setattr(self, fname, lambda : etree.XML(xml, etree_parser))
setattr(self, fname + '_xml', lambda : xml)
else:
def set_property(root, fname):
@@ -184,7 +184,7 @@ class BenchMarkBase(object):
t = current_time()
root = self.etree.Element('{abc}rootnode')
for ch1 in atoz:
- el = SubElement(root, "{bcd}"+ch1*5, attributes)
+ el = SubElement(root, "{abc}"+ch1*5, attributes)
el.text = text
for ch2 in atoz:
for i in range(20 * TREE_FACTOR):
@@ -201,7 +201,7 @@ class BenchMarkBase(object):
root = self.etree.Element('{abc}rootnode')
for ch1 in atoz:
for i in range(20 * TREE_FACTOR):
- el = SubElement(root, "{bcd}"+ch1*5, attributes)
+ el = SubElement(root, "{abc}"+ch1*5, attributes)
el.text = text
for ch2 in atoz:
SubElement(el, "{cdefg}%s%05d" % (ch2, i))
@@ -232,10 +232,10 @@ class BenchMarkBase(object):
root = self.etree.Element('{abc}rootnode')
children = [root]
for ch1 in self.atoz:
- el = SubElement(root, "{bcd}"+ch1*5, attributes)
+ el = SubElement(root, "{abc}"+ch1*5, attributes)
el.text = text
SubElement(el, "{cdefg}a00001", attributes)
- SubElement(el, "{cdefg}a00002", attributes)
+ SubElement(el, "{cdefg}z00000", attributes)
t = current_time() - t
return (root, t)