[Checkins] SVN: z3c.pt/trunk/ Added tests for compilation speed and path-expression performance.

Malthe Borch mborch at gmail.com
Tue Mar 18 21:46:23 EDT 2008


Log message for revision 84772:
  Added tests for compilation speed and path-expression performance.

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

-=-
Modified: z3c.pt/trunk/benchmark/benchmark/tests.py
===================================================================
--- z3c.pt/trunk/benchmark/benchmark/tests.py	2008-03-19 01:45:02 UTC (rev 84771)
+++ z3c.pt/trunk/benchmark/benchmark/tests.py	2008-03-19 01:46:22 UTC (rev 84772)
@@ -20,14 +20,14 @@
         return wrapper
     return decorator
 
-def timing(func, **kwargs):
+def timing(func, *args, **kwargs):
     t1 = t2 = time.time()
     i = 0
     while t2 - t1 < 3:
-        func(**kwargs)
+        func(*args, **kwargs)
         i += 1
         t2 = time.time()
-    return (t2-t1)/i
+    return 100*(t2-t1)/i
            
 class BenchmarkTestCase(unittest.TestCase):
     helloworld_z3c = z3c.pt.PageTemplate("""\
@@ -41,7 +41,7 @@
     Hello World!
     </div>""", 'text/xhtml')
     
-    bigtable_z3c = z3c.pt.PageTemplate("""\
+    bigtable_python_z3c = z3c.pt.PageTemplate("""\
     <table xmlns="http://www.w3.org/1999/xhtml"
     xmlns:tal="http://xml.zope.org/namespaces/tal">
     <tr tal:repeat="row table">
@@ -53,13 +53,39 @@
     </tr>
     </table>""")
 
-    bigtable_zope = zope.pagetemplate.pagetemplate.PageTemplate()
-    bigtable_zope.pt_edit("""\
+    bigtable_path_z3c = z3c.pt.PageTemplate("""\
     <table xmlns="http://www.w3.org/1999/xhtml"
+    xmlns:tal="http://xml.zope.org/namespaces/tal"
+    tal:default-expression="path">
+    <tr tal:repeat="row table">
+    <td tal:repeat="c row/values">
+    <span tal:define="d python: c + 1"
+    tal:attributes="class string:column-${d}"
+    tal:content="d" />
+    </td>
+    </tr>
+    </table>""")
+
+    bigtable_python_zope = zope.pagetemplate.pagetemplate.PageTemplate()
+    bigtable_python_zope.pt_edit("""\
+    <table xmlns="http://www.w3.org/1999/xhtml"
     xmlns:tal="http://xml.zope.org/namespaces/tal">
-    <tr tal:repeat="row options/table">
+    <tr tal:repeat="row python: options['table']">
     <td tal:repeat="c python: row.values()">
     <span tal:define="d python: c + 1"
+    tal:attributes="class python:'column-'+str(d)"
+    tal:content="d" />
+    </td>
+    </tr>
+    </table>""", 'text/xhtml')
+
+    bigtable_path_zope = zope.pagetemplate.pagetemplate.PageTemplate()
+    bigtable_path_zope.pt_edit("""\
+    <table xmlns="http://www.w3.org/1999/xhtml"
+    xmlns:tal="http://xml.zope.org/namespaces/tal">
+    <tr tal:repeat="row options/table">
+    <td tal:repeat="c row/values">
+    <span tal:define="d python: c + 1"
     tal:attributes="class string:column-${d}"
     tal:content="d" />
     </td>
@@ -82,18 +108,42 @@
         print "zope.pagetemplate: %.2f" % t_zope
         print "                   %.2fX" % (t_zope/t_z3c)
 
-    @benchmark(u"Big table")
-    def testBigTable(self):
+    @benchmark(u"Big table (python)")
+    def testBigTablePython(self):
         table = [dict(a=1,b=2,c=3,d=4,e=5,f=6,g=7,h=8,i=9,j=10) \
                  for x in range(1000)]
 
-        t_z3c = timing(self.bigtable_z3c, table=table)
-        t_zope = timing(self.bigtable_zope, table=table)
+        t_z3c = timing(self.bigtable_python_z3c, table=table)
+        t_zope = timing(self.bigtable_python_zope, table=table)
 
         print "z3c.pt:            %.2f" % t_z3c
         print "zope.pagetemplate: %.2f" % t_zope
         print "                   %.2fX" % (t_zope/t_z3c)
 
+    @benchmark(u"Big table (path)")
+    def testBigTablePath(self):
+        table = [dict(a=1,b=2,c=3,d=4,e=5,f=6,g=7,h=8,i=9,j=10) \
+                 for x in range(1000)]
+
+        t_z3c = timing(self.bigtable_path_z3c, table=table, request=object())
+        t_zope = timing(self.bigtable_path_zope, table=table)
+
+        print "z3c.pt:            %.2f" % t_z3c
+        print "zope.pagetemplate: %.2f" % t_zope
+        print "                   %.2fX" % (t_zope/t_z3c)
+
+    @benchmark(u"Compilation")
+    def testCompilation(self):
+        table = [dict(a=1,b=2,c=3,d=4,e=5,f=6,g=7,h=8,i=9,j=10) \
+                 for x in range(1000)]
+
+        t_z3c = timing(self.bigtable_python_z3c.cook, ['table'])
+        t_zope = timing(self.bigtable_python_zope._cook)
+
+        print "z3c.pt:            %.2f" % t_z3c
+        print "zope.pagetemplate: %.2f" % t_zope
+        print "                   %.2fX" % (t_zope/t_z3c)
+
 def test_suite():
     return unittest.makeSuite(BenchmarkTestCase)
 

Modified: z3c.pt/trunk/setup.py
===================================================================
--- z3c.pt/trunk/setup.py	2008-03-19 01:45:02 UTC (rev 84771)
+++ z3c.pt/trunk/setup.py	2008-03-19 01:46:22 UTC (rev 84772)
@@ -1,6 +1,6 @@
 from setuptools import setup, find_packages
 
-version = '0.8'
+version = '0.8.1'
 
 setup(name='z3c.pt',
       version=version,



More information about the Checkins mailing list