[Lxml-checkins] r33791 - in lxml/trunk: . benchmark src/lxml
scoder at codespeak.net
scoder at codespeak.net
Fri Oct 27 08:52:11 CEST 2006
Author: scoder
Date: Fri Oct 27 08:52:09 2006
New Revision: 33791
Modified:
lxml/trunk/CHANGES.txt
lxml/trunk/benchmark/bench_objectify.py
lxml/trunk/src/lxml/objectify.pyx
Log:
fixes in bench_objectify.py, some more benchmarks
Modified: lxml/trunk/CHANGES.txt
==============================================================================
--- lxml/trunk/CHANGES.txt (original)
+++ lxml/trunk/CHANGES.txt Fri Oct 27 08:52:09 2006
@@ -8,6 +8,8 @@
Features added
--------------
+* Data elements in objectify support repr(), which is now used by dump()
+
* Source distribution now ships with a patched Pyrex
* New C-API function makeElement() to create new elements with text,
Modified: lxml/trunk/benchmark/bench_objectify.py
==============================================================================
--- lxml/trunk/benchmark/bench_objectify.py (original)
+++ lxml/trunk/benchmark/bench_objectify.py Fri Oct 27 08:52:09 2006
@@ -2,12 +2,6 @@
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
@@ -17,10 +11,21 @@
class BenchMark(benchbase.BenchMarkBase):
def __init__(self, lib):
- benchbase.BenchMarkBase.__init__(self, lib, parser)
+ from lxml import etree, objectify
+ self.objectify = objectify
+ parser = etree.XMLParser(remove_blank_text=True)
+ lookup = objectify.ObjectifyElementClassLookup()
+ parser.setElementClassLookup(lookup)
+ super(BenchMark, self).__init__(etree, parser)
+
+ def bench_attribute(self, root):
+ "1 2 4"
+ for i in repeat(None, 3000):
+ root.zzzzz
- def bench_attributes(self, root):
+ def bench_attribute_cached(self, root):
"1 2 4"
+ cache = root.zzzzz
for i in repeat(None, 3000):
root.zzzzz
@@ -38,13 +43,13 @@
def bench_objectpath(self, root):
"1 2 4"
- path = objectify.ObjectPath(".zzzzz")
+ path = self.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")
+ path = self.objectify.ObjectPath(".zzzzz.{cdefg}z00000")
for i in repeat(None, 3000):
path(root)
@@ -52,9 +57,32 @@
"1 2 4"
cache1 = root.zzzzz
cache2 = cache1['{cdefg}z00000']
- path = objectify.ObjectPath(".zzzzz.{cdefg}z00000")
+ path = self.objectify.ObjectPath(".zzzzz.{cdefg}z00000")
for i in repeat(None, 3000):
path(root)
+ @with_text(text=True, utext=True, no_text=True)
+ def bench_annotate(self, root):
+ self.objectify.annotate(root)
+
+ def bench_descendantpaths(self, root):
+ root.descendantpaths()
+
+ @with_text(text=True)
+ def bench_type_inference(self, root):
+ "1 2 4"
+ el = root.aaaaa
+ for i in repeat(None, 1000):
+ el.getchildren()
+
+ @with_text(text=True)
+ def bench_type_inference_annotated(self, root):
+ "1 2 4"
+ el = root.aaaaa
+ self.objectify.annotate(el)
+ for i in repeat(None, 1000):
+ el.getchildren()
+
+
if __name__ == '__main__':
benchbase.main(BenchMark)
Modified: lxml/trunk/src/lxml/objectify.pyx
==============================================================================
--- lxml/trunk/src/lxml/objectify.pyx (original)
+++ lxml/trunk/src/lxml/objectify.pyx Fri Oct 27 08:52:09 2006
@@ -1,7 +1,8 @@
from etreepublic cimport _Document, _Element, ElementBase
from etreepublic cimport _ElementIterator, ElementClassLookup
from etreepublic cimport elementFactory, import_etree, textOf
-from python cimport isinstance, issubclass, callable, getattr, _cstr, Py_ssize_t
+from python cimport str, repr, isinstance, issubclass, callable, getattr
+from python cimport _cstr, Py_ssize_t
cimport etreepublic as cetree
cimport python
cimport tree
@@ -27,8 +28,6 @@
float = __builtin__.float
cdef object bool
bool = __builtin__.bool
-cdef object str
-str = __builtin__.str
cdef object pow
pow = __builtin__.pow
cdef object abs
@@ -487,6 +486,9 @@
def __str__(self):
return textOf(self._c_node) or ''
+ def __repr__(self):
+ return textOf(self._c_node) or ''
+
def __setText(self, s):
"""For use in subclasses only. Don't use unless you know what you are
doing.
@@ -518,6 +520,9 @@
def __str__(self):
return str(self._type(textOf(self._c_node)))
+ def __repr__(self):
+ return repr(self._type(textOf(self._c_node)))
+
# def __oct__(self):
# def __hex__(self):
@@ -604,6 +609,9 @@
def __get__(self):
return textOf(self._c_node) or ''
+ def __repr__(self):
+ return repr(textOf(self._c_node) or '')
+
def strlen(self):
text = textOf(self._c_node)
if text is None:
@@ -654,6 +662,9 @@
def __str__(self):
return "None"
+ def __repr__(self):
+ return "None"
+
def __nonzero__(self):
return False
@@ -705,6 +716,12 @@
else:
return "False"
+ def __repr__(self):
+ if self._boolval():
+ return "True"
+ else:
+ return "False"
+
property pyval:
def __get__(self):
return self.__nonzero__()
@@ -931,20 +948,26 @@
cdef object _dump(_Element element, int indent):
indentstr = " " * indent
- if hasattr(element, "pyval"):
- value = element.pyval
+ if isinstance(element, ObjectifiedDataElement):
+ value = repr(element)
else:
value = textOf(element._c_node)
- if value and not value.strip():
- value = None
- result = "%s%s = %r [%s]\n" % (indentstr, element.tag,
+ if value is not None:
+ if python.PyString_GET_SIZE( value.strip() ) == 0:
+ value = None
+ else:
+ value = repr(value)
+ result = "%s%s = %s [%s]\n" % (indentstr, element.tag,
value, type(element).__name__)
xsi_ns = "{%s}" % XML_SCHEMA_INSTANCE_NS
pytype_ns = "{%s}" % PYTYPE_NAMESPACE
for name, value in cetree.iterattributes(element, 3):
- if name == PYTYPE_ATTRIBUTE and value == TREE_PYTYPE:
- continue
- name = name.replace(xsi_ns, 'xsi:').replace(pytype_ns, 'py:')
+ if name == PYTYPE_ATTRIBUTE:
+ if value == TREE_PYTYPE:
+ continue
+ else:
+ name = name.replace(pytype_ns, 'py:')
+ name = name.replace(xsi_ns, 'xsi:')
result = result + "%s * %s = %r\n" % (indentstr, name, value)
indent = indent + 1
More information about the lxml-checkins
mailing list