I have found two simple benchmark on the genshi site. The basic benchmark is not a good benchmark, since the tests are not all equivalent. I have added a test for Nevow (the patch is attached). Before sending the patch to the genshi developers, I want to be sure that the code is the best possible. Here is the results: basic ===== Django: 1.35 ms Cheetah: 0.64 ms Nevow: 1.88 ms bigtable ======== Djange template 370.68 ms Nevow 947.84 ms Thanks and regards Manlio Perillo Index: bigtable.py =================================================================== --- bigtable.py (revisione 565) +++ bigtable.py (copia locale) @@ -9,10 +9,14 @@ import sys import timeit from StringIO import StringIO -from genshi.builder import tag -from genshi.template import MarkupTemplate try: + from genshi.builder import tag + from genshi.template import MarkupTemplate +except ImportError: + MarkupTemplate = None + +try: from elementtree import ElementTree as et except ImportError: et = None @@ -45,10 +49,16 @@ except ImportError: MyghtyInterpreter = None +try: + from nevow import inevow, rend, loaders +except ImportError: + inevow = None + 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)] -genshi_tmpl = MarkupTemplate(""" +if MarkupTemplate: + genshi_tmpl = MarkupTemplate(""" <table xmlns:py="http://genshi.edgewall.org/"> <tr py:for="row in table"> <td py:for="c in row.values()" py:content="c"/> @@ -56,7 +66,7 @@ </table> """) -genshi_tmpl2 = MarkupTemplate(""" + genshi_tmpl2 = MarkupTemplate(""" <table xmlns:py="http://genshi.edgewall.org/">$table</table> """) @@ -184,11 +194,44 @@ </table>""") cs.render() +if inevow: + class NevowPage(rend.Page): + docFactory = loaders.xmlstr(""" +<table xmlns:n="http://nevow.com/ns/nevow/0.1" n:render="table"> + <tr n:pattern="row"> + <td n:pattern="col"><n:slot name="item" /></td> + </tr> +</table>""") + def render_table(self, ctx, data): + tag = ctx.tag + l = [] + rowPattern = tag.patternGenerator('row') + + for row in table: + tr = rowPattern() + colPattern = tr.patternGenerator('col') + ll = [] + + for col in row.values(): + td = colPattern() + td.fillSlots('item', col) + ll.append(td) + + l.append(tr[ll]) + + return tag[l] + + def test_nevow(): + """Nevow""" + + NevowPage().renderSynchronously() + + def run(which=None, number=10): tests = ['test_builder', 'test_genshi', 'test_genshi_builder', 'test_myghty', 'test_kid', 'test_kid_et', 'test_et', 'test_cet', 'test_clearsilver', - 'test_django'] + 'test_django', 'test_nevow'] if which: tests = filter(lambda n: n[5:] in which, tests) Index: basic.py =================================================================== --- basic.py (revisione 565) +++ basic.py (copia locale) @@ -4,7 +4,7 @@ import sys import timeit -__all__ = ['clearsilver', 'myghty', 'django', 'kid', 'genshi', 'cheetah'] +__all__ = ['clearsilver', 'myghty', 'django', 'kid', 'genshi', 'cheetah', 'nevow'] def genshi(dirname, verbose=False): from genshi.template import TemplateLoader @@ -105,11 +105,48 @@ return render def nevow(dirname, verbose=False): - # FIXME: can't figure out the API - from nevow.loaders import xmlfile - template = xmlfile('template.xml', templateDir=dirname).load() + from nevow import rend, loaders + + + class Base(rend.Page): + docFactory = loaders.xmlfile('template.xhtml', templateDir=dirname) + template = None # The template to be used, in derived class + + def render_title(self, ctx, data): + return 'Just a test' + + def macro_main(self, ctx): + return ctx.tag[ + loaders.xmlfile(self.template, ignoreDocType=True, templateDir=dirname) + ] + + class Main(Base): + template = 'main.xhtml' + + def __init__(self, items): + self.items = items + + def render_loop(self, ctx, data): + tag = ctx.tag + if not self.items: + return tag + + l = [] + itemPattern = tag.patternGenerator('item') + + for item in self.items: + li = itemPattern() + li.fillSlots('item', item) + l.append(li) + + l[-1].attributes['class'] = 'last' + return tag[l] + + + root = Main(['Number %d' % num for num in range(1, 15)]) + def render(): - print template + return root.renderSynchronously() if verbose: print render() Index: nevow/main.xhtml =================================================================== --- nevow/main.xhtml (revisione 0) +++ nevow/main.xhtml (revisione 0) @@ -0,0 +1,10 @@ +<!DOCTYPE html + PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<n:invisible xmlns="http://www.w3.org/1999/xhtml" + xmlns:n="http://nevow.com/ns/nevow/0.1"> + <h2>Loop</h2> + <ul n:render="loop"> + <li n:pattern="item"><n:slot name="item" /></li> + </ul> +</n:invisible> Proprietà modificate su: nevow/main.xhtml ___________________________________________________________________ Nome: svn:keywords + Id Index: nevow/template.xhtml =================================================================== --- nevow/template.xhtml (revisione 0) +++ nevow/template.xhtml (revisione 0) @@ -0,0 +1,20 @@ +<!DOCTYPE html + PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:n="http://nevow.com/ns/nevow/0.1" + lang="en"> + <head> + <title n:render="title" /> + </head> + + <body> + <div id="header"> + <h1 n:render="title" /> + </div> + + <n:invisible n:macro="main" /> + + <div id="footer"></div> + </body> +</html> Proprietà modificate su: nevow/template.xhtml ___________________________________________________________________ Nome: svn:keywords + Id