[Lxml-checkins] r33793 - lxml/trunk/benchmark

scoder at codespeak.net scoder at codespeak.net
Fri Oct 27 08:54:53 CEST 2006


Author: scoder
Date: Fri Oct 27 08:54:53 2006
New Revision: 33793

Modified:
   lxml/trunk/benchmark/bench_objectify.py
Log:
fixes in bench_objectify.py, some more benchmarks

Modified: lxml/trunk/benchmark/bench_objectify.py
==============================================================================
--- lxml/trunk/benchmark/bench_objectify.py	(original)
+++ lxml/trunk/benchmark/bench_objectify.py	Fri Oct 27 08:54:53 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)


More information about the lxml-checkins mailing list