[Checkins] SVN: z3c.pt/trunk/ Set up benchmark suite as separate testrunner.

Malthe Borch mborch at gmail.com
Mon Mar 17 06:31:55 EDT 2008


Log message for revision 84737:
  Set up benchmark suite as separate testrunner.

Changed:
  A   z3c.pt/trunk/benchmark/
  A   z3c.pt/trunk/benchmark/benchmark/
  A   z3c.pt/trunk/benchmark/benchmark/__init__.py
  A   z3c.pt/trunk/benchmark/benchmark/tests.py
  A   z3c.pt/trunk/benchmark/setup.py
  U   z3c.pt/trunk/buildout.cfg
  D   z3c.pt/trunk/z3c/pt/BENCHMARKS.txt
  U   z3c.pt/trunk/z3c/pt/tests/test_doctests.py

-=-
Added: z3c.pt/trunk/benchmark/benchmark/__init__.py
===================================================================
--- z3c.pt/trunk/benchmark/benchmark/__init__.py	                        (rev 0)
+++ z3c.pt/trunk/benchmark/benchmark/__init__.py	2008-03-17 10:31:55 UTC (rev 84737)
@@ -0,0 +1 @@
+#

Added: z3c.pt/trunk/benchmark/benchmark/tests.py
===================================================================
--- z3c.pt/trunk/benchmark/benchmark/tests.py	                        (rev 0)
+++ z3c.pt/trunk/benchmark/benchmark/tests.py	2008-03-17 10:31:55 UTC (rev 84737)
@@ -0,0 +1,102 @@
+import os
+import unittest
+import time
+import sys
+
+reload(sys)
+sys.setdefaultencoding('utf-8')
+
+import zope.component.testing
+import zope.configuration.xmlconfig
+
+import zope.pagetemplate.pagetemplatefile
+import z3c.pt
+
+def benchmark(title):
+    def decorator(f):
+        def wrapper(*args):
+            print "==========================\n %s\n==========================" % title
+            return f(*args)
+        return wrapper
+    return decorator
+
+def timing(func, **kwargs):
+    t1 = t2 = time.time()
+    i = 0
+    while t2 - t1 < 3:
+        func(**kwargs)
+        i += 1
+        t2 = time.time()
+    return (t2-t1)/i
+           
+class BenchmarkTestCase(unittest.TestCase):
+    helloworld_z3c = z3c.pt.PageTemplate("""\
+    <div xmlns="http://www.w3.org/1999/xhtml">
+    Hello World!
+    </div>""")
+
+    helloworld_zope = zope.pagetemplate.pagetemplate.PageTemplate()
+    helloworld_zope.pt_edit("""\
+    <div xmlns="http://www.w3.org/1999/xhtml">
+    Hello World!
+    </div>""", 'text/xhtml')
+    
+    bigtable_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">
+    <td tal:repeat="c row.values()">
+    <span tal:define="d c + 1"
+    tal:attributes="class 'column-' + str(d)"
+    tal:content="d" />
+    </td>
+    </tr>
+    </table>""")
+
+    bigtable_zope = zope.pagetemplate.pagetemplate.PageTemplate()
+    bigtable_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 python: row.values()">
+    <span tal:define="d python: c + 1"
+    tal:attributes="class string:column-${d}"
+    tal:content="d" />
+    </td>
+    </tr>
+    </table>""", 'text/xhtml')
+
+    def setUp(suite):
+        zope.component.testing.setUp(suite)
+        zope.configuration.xmlconfig.XMLConfig('configure.zcml', z3c.pt)()
+
+    def tearDown(suite):
+        zope.component.testing.tearDown(suite)
+
+    @benchmark(u"Hello World")
+    def testHelloWorld(self):
+        t_z3c = timing(self.helloworld_z3c)
+        t_zope = timing(self.helloworld_zope)
+
+        print "z3c.pt:            %.2f" % t_z3c
+        print "zope.pagetemplate: %.2f" % t_zope
+        print "                   %.2fX" % (t_zope/t_z3c)
+
+    @benchmark(u"Big table")
+    def testBigTable(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)
+
+        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)
+
+if __name__ == "__main__":
+    unittest.main(defaultTest="test_suite")
+

Added: z3c.pt/trunk/benchmark/setup.py
===================================================================
--- z3c.pt/trunk/benchmark/setup.py	                        (rev 0)
+++ z3c.pt/trunk/benchmark/setup.py	2008-03-17 10:31:55 UTC (rev 84737)
@@ -0,0 +1,26 @@
+from setuptools import setup, find_packages
+import sys, os
+
+version = '0.1'
+
+setup(name='benchmark',
+      version=version,
+      description="Benchmark-suite for z3c.pt.",
+      long_description="""\
+      """,
+      keywords='',
+      author='Malthe Borch',
+      author_email='mborch at gmail.com',
+      url='',
+      license='',
+      packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
+      include_package_data=True,
+      zip_safe=False,
+      install_requires=[
+         'zope.pagetemplate',
+         'z3c.pt',
+      ],
+      entry_points="""
+      # -*- Entry points: -*-
+      """,
+      )

Modified: z3c.pt/trunk/buildout.cfg
===================================================================
--- z3c.pt/trunk/buildout.cfg	2008-03-17 10:12:50 UTC (rev 84736)
+++ z3c.pt/trunk/buildout.cfg	2008-03-17 10:31:55 UTC (rev 84737)
@@ -1,8 +1,13 @@
 [buildout]
-develop = .
-parts = test
+develop = . benchmark
+eggs = z3c.pt
+parts = test benchmark
 find-links = http://download.zope.org/distribution/
 
 [test]
 recipe = zc.recipe.testrunner
-eggs = z3c.pt
\ No newline at end of file
+eggs = z3c.pt
+
+[benchmark]
+recipe = zc.recipe.testrunner
+eggs = benchmark
\ No newline at end of file

Deleted: z3c.pt/trunk/z3c/pt/BENCHMARKS.txt
===================================================================
--- z3c.pt/trunk/z3c/pt/BENCHMARKS.txt	2008-03-17 10:12:50 UTC (rev 84736)
+++ z3c.pt/trunk/z3c/pt/BENCHMARKS.txt	2008-03-17 10:31:55 UTC (rev 84737)
@@ -1,113 +0,0 @@
-Benchmarks
-==========
-
-These benchmarks should not be taken too seriously but they do give an
-idea of how this package measures up to Zope's default TAL
-engine. Also included is a comparison to a pure python implementation.
-
-Results
--------
-
-                  zope.pagetemplate     z3c.pt    pure python
-Hello World        3.6                  1         0.02        
-1000 x 10 table   10.6*                 1         0.53
-
-There's a setup cost in using a template language which explains the
-50x factor in the 'Hello World' benchmark versus a pure python
-implementation.
-
-Certainly a specialized implementation will always be faster.
-
-*) This benchmark was made with the default encoding set to
- UTF-8. There's a penalty of 10-15% when using an encoding that does
- not coerce unicode gracefully to strings.
-
-Setup
------
-
-  >>> from zope.component import provideUtility
-
-  >>> from z3c.pt.expressions import PythonTranslation
-  >>> provideUtility(PythonTranslation(), name="python")
-
-  >>> from z3c.pt.expressions import PathTranslation
-  >>> provideUtility(PathTranslation(), name="path")
-
-Benchmark source code
----------------------
-
-  >>> from z3c.pt import PageTemplate
-  >>> from zope.pagetemplate.pagetemplate import PageTemplate as z3PageTemplate
-
-Hello World:
-
-  >>> template = PageTemplate("""\
-  ... <div xmlns="http://www.w3.org/1999/xhtml">
-  ...   Hello World!
-  ... </div>""")
-
-  >>> # for i in range(90000): a = template()
-
-  >>> template = z3PageTemplate()
-  >>> template.pt_edit("""\
-  ... <div xmlns="http://www.w3.org/1999/xhtml">
-  ...   Hello World!
-  ... </div>""", 'text/xhtml')
-
-  >>> # for i in range(90000): a = template()  
-
-  >>> def hello_world():
-  ...     return u"""\
-  ... <div>
-  ...   Hello World!
-  ... </div>"""
-
-  >>> # for i in range(9000000): a = hello_world()
-
-1000 x 10 table:
-  
-  >>> 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)]
-
-  >>> template = PageTemplate("""\
-  ... <table xmlns="http://www.w3.org/1999/xhtml"
-  ...        xmlns:tal="http://xml.zope.org/namespaces/tal">
-  ...   <tr tal:repeat="row table">
-  ...      <td tal:repeat="c row.values()">
-  ...          <span tal:define="d c + 1"
-  ...                tal:attributes="class 'column-' + str(d)"
-  ...                tal:content="d" />
-  ...      </td>
-  ...   </tr>
-  ... </table>""")
-
-  >>> # for i in range(40): a = template(table=table)
-  
-  >>> template = z3PageTemplate()
-  >>> template.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 python: row.values()">
-  ...          <span tal:define="d python: c + 1"
-  ...                tal:attributes="class string:column-${d}"
-  ...                tal:content="d" />
-  ...      </td>
-  ...   </tr>
-  ... </table>""", 'text/xhtml')
-
-  >>> # for i in range(40): a = template(table=table)
-
-  >>> from StringIO import StringIO
-  >>> def bigtable(table):
-  ...   out = StringIO()
-  ...   for row in table:
-  ...      out.write('<tr>')
-  ...      for c in row.values():
-  ...         d = c+1
-  ...         out.write('<td><span class="column-%d">%s</span></td>' % (d, d))
-  ...      out.write('</tr>')
-  ...   return out.getvalue()
-  
-  >>> # for i in range(40): a = bigtable(table=table)
-

Modified: z3c.pt/trunk/z3c/pt/tests/test_doctests.py
===================================================================
--- z3c.pt/trunk/z3c/pt/tests/test_doctests.py	2008-03-17 10:12:50 UTC (rev 84736)
+++ z3c.pt/trunk/z3c/pt/tests/test_doctests.py	2008-03-17 10:31:55 UTC (rev 84737)
@@ -14,7 +14,7 @@
     zope.configuration.xmlconfig.XMLConfig('configure.zcml', z3c.pt)()
 
 def test_suite():
-    filesuites = ('README.txt', 'BENCHMARKS.txt', 'translation.txt', 'i18n.txt', 'codegen.txt')
+    filesuites = ('README.txt', 'translation.txt', 'i18n.txt', 'codegen.txt')
     testsuites = ('z3c.pt.translation', 'z3c.pt.clauses', 'z3c.pt.expressions')
 
     return unittest.TestSuite(



More information about the Checkins mailing list