[Twisted-web] [Nevow] template performance

Manlio Perillo manlio_perillo at libero.it
Fri Dec 15 07:44:50 CST 2006


Tristan Seligmann ha scritto:
> * Manlio Perillo <manlio_perillo at libero.it> [2006-12-15 13:33:55 +0100]:
> 
>> manlio at synapsis:~/projects/tests/nevow$ python static2.py
>> 9.85 usec/pass
>>
>> manlio at synapsis:~/projects/tests/django$ python static2.py
>> 13.31 usec/pass
> 
> Is this python 2.4 or 2.5? The string handling speed-ups in 2.5 have a
> fairly substantial impact on Nevow rendering speed, I believe.
> 

Python 2.4.
However Python 2.5 should speed up Django, too.

>> Nevow for every data object calls inevow.IContainer.child.
>> The problem can be here, since it is called 25 times (the number of rows 
>> in the table)
> 
> That's easy enough to fix, just don't use data specials :)
> 

Right!


class Main(rend.Page):
     docFactory = loaders.xmlfile("template3.xhtml")


     def render_header(self, ctx, data):
         def renderRow(data):
             for i in data:
                 yield tags.th[str(i)]

         data = range(COLS)
         return ctx.tag[renderRow(data)]

     def render_table(self, ctx, data):
         def renderRow(data):
             for i in data:
                 yield tags.td[str(i)]

         def renderTable(data):
             for i in data:
                 yield tags.tr[renderRow(i)]

         data =  [
             [random.random() for j in range(COLS)]
             for i in range(ROWS)
             ]
         return ctx.tag[renderTable(data)]

<!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" xml:lang="">
   <head>
     <title>Test Nevow performance</title>
   </head>
   <body>
     <table>
       <caption>RandomTable</caption>
       <thead>
         <tr n:render="header" />
       </thead>
       <tbody n:render="table" />
     </table>
   </body>
</html>


manlio at synapsis:~/projects/tests/nevow$ python static3.py
75.71 usec/pass


4.5 times faster!


I suspect that using directly flat.flatten is even better but, then, 
what's the use of the templating system?



P.S.
Django.template does not escapes string.
If I add the filter escape, performance drops from
33.58 usec/pass to 47.16 usec/pass.



Regards  Manlio Perillo



More information about the Twisted-web mailing list