[Lxml-checkins] r33747 - lxml/trunk/benchmark
scoder at codespeak.net
scoder at codespeak.net
Thu Oct 26 08:54:52 CEST 2006
Author: scoder
Date: Thu Oct 26 08:54:50 2006
New Revision: 33747
Added:
lxml/trunk/benchmark/bench_objectify.py
Modified:
lxml/trunk/benchmark/benchbase.py
Log:
cleanup in benchmarks, new objectify benchmark class
Added: lxml/trunk/benchmark/bench_objectify.py
==============================================================================
--- (empty file)
+++ lxml/trunk/benchmark/bench_objectify.py Thu Oct 26 08:54:50 2006
@@ -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)
Modified: lxml/trunk/benchmark/benchbase.py
==============================================================================
--- lxml/trunk/benchmark/benchbase.py (original)
+++ lxml/trunk/benchmark/benchbase.py Thu Oct 26 08:54:50 2006
@@ -96,7 +96,7 @@
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 @@
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 @@
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 @@
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 @@
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)
More information about the lxml-checkins
mailing list