[Checkins] SVN: z3c.pt/trunk/benchmark/benchmark/tests.py Added comparison to an lxml-based XML tree manipulation and serialization.

Malthe Borch mborch at gmail.com
Mon Aug 11 13:55:56 EDT 2008


Log message for revision 89676:
  Added comparison to an lxml-based XML tree manipulation and serialization.

Changed:
  U   z3c.pt/trunk/benchmark/benchmark/tests.py

-=-
Modified: z3c.pt/trunk/benchmark/benchmark/tests.py
===================================================================
--- z3c.pt/trunk/benchmark/benchmark/tests.py	2008-08-11 17:24:49 UTC (rev 89675)
+++ z3c.pt/trunk/benchmark/benchmark/tests.py	2008-08-11 17:55:56 UTC (rev 89676)
@@ -13,6 +13,8 @@
 import z3c.pt
 from z3c.pt import generation
 
+from lxml import etree
+
 def benchmark(title):
     def decorator(f):
         def wrapper(*args):
@@ -30,6 +32,21 @@
         t2 = time.time()
     return 100*(t2-t1)/i
 
+def bigtable_python_lxml(table=None):
+    root = etree.Element("html")
+    for r in table:
+        row = etree.Element("tr")
+        for c in r.values():
+            d = c + 1
+            col = etree.Element("td")
+            span = etree.Element("span")
+            span.attrib['class'] = 'column-%d' % d
+            span.text = str(d)
+            col.append(span)
+            row.append(col)
+        root.append(row)
+    return etree.tostring(root)
+
 class BaseTestCase(unittest.TestCase):
 
     table = [dict(a=1,b=2,c=3,d=4,e=5,f=6,g=7,h=8,i=9,j=10) \
@@ -121,10 +138,15 @@
 
         t_z3c = timing(self.bigtable_python_z3c, table=table)
         t_zope = timing(self.bigtable_python_zope, table=table)
+        t_lxml = timing(bigtable_python_lxml, table=table)
 
+        print "zope.pagetemplate: %.2f" % t_zope
+        print "lxml:              %.2f" % t_lxml
+        print "--------------------------"
         print "z3c.pt:            %.2f" % t_z3c
-        print "zope.pagetemplate: %.2f" % t_zope
-        print "                   %.2fX" % (t_zope/t_z3c)
+        print "--------------------------"
+        print "ratio to zpt:      %.2fX" % (t_zope/t_z3c)
+        print "ratio to lxml:     %.2fX" % (t_lxml/t_z3c)
 
     @benchmark(u"Big table (path)")
     def testBigTablePath(self):



More information about the Checkins mailing list