Webware vs. PHP - performance comparision!!!

Richard Shea richardshea at fastmail.fm
Mon Oct 6 06:22:16 EDT 2003


JZ <jroznfgre at jngpugbjreXEBCXNbet.cy> wrote in message news:<aud1ovc0pg8jgs6v1kqlqos72k8jrj0r22 at 4ax.com>...
> I created an application based on Webware and Python. I was surprised
> why it works so slowly. So I decided to check how fast are different
> Python solutions against PHP. 

I was interested to see your results. They do suggest that Python
isn't all that good doing this sort of thing. However a couple of
things puzzled me about them and I wondered if perhaps the test could
stand some improvements.

First the 3 seconds for the PHP seemed remarkably slow to me. I use
PHP on a *much* less powerful machine than yours (albeit a different
OS) and that figure does seem quite slow to me for what the script is
doing.

Second if I understand your test correctly you switch from webware to
webware/templates to cheetah ... etc and take your timing immediately.
I'm just wondering whether a better (or at least more representative)
test would be to allow a different (avoid any form of caching) script
to run with each technique before allowing your timed script to run
... in this way any "startup costs" are taken by the dummy script
before your timed script (I'm making the assumption here that in the
real world you'd use webware or cheetah not expect your server to
switch between them from request to request)

Last thing is just an instinctive thing can't really say why but those
first three Python based techniques differ in time by less than 1% ...
just seems a bit strange to me that they would all be quite so similar
in speed.

Anyway I was interested to see the numbers and maybe people a lot more
knowledgeable then me can throw some light on them.

regards

richard shea.


> 
> My hardware and software settings are:
> 
> WindowsXP Pro, Athlon XP2800+, 512DDRdual,
> 
> Python 3.3.2 stable
> Webware & WebKit & mod_webkit.dll  CVS 2003-09-19
> Cheetah CVS 2003-09-19
> Spyce 3.11
> vs.
> PHP 4.3.3 stable
> MMCache 2.4.1
> 
> For page request I used wget.
> 
> My testing code is
> =============
> import os, time
> url = [
>     r'http://localhost/WK/test/test1/testpython.py',
>     r'http://localhost/WK/test/test1/testcheetah.tmpl',
>     r'http://localhost/WK/test/test1/testcheetah.py',
>     r'http://localhost/WK/test/test1/testpsp.psp',
>     r'http://localhost/testphp.php',
>     r'http://localhost/testspyce.spy',
>     ]
> for u in url:
>     t1=time.time()
>     print '>>>%s' % u,
>     os.system('wget  -m %s -o stress.log' % u)
>     t = time.time()-t1
>     print ' => time: %f s' % t
> 
> testpython.py:
> ===========
> from WebKit.Page import Page
> class testpython(Page):
>     def writeHTML(self):
>         cpunter = 100
>         i=int(self.request().field('c', 0))
>         self.write('<p>Try: %d</p>' % i)
>         if 0 < i <100:
>             i += 1
>             self.write("<a href='http://%s?c=%d'>next</a>" %\
>                             (self.request().serverURL(), i))
>         else:
>             self.write("<a href='http://%s?c=1'>next</a>" %\
>                             self.request().serverURL())
> 
> testcheetah.tmpl:
> =============
> #set $counter = 100
> #set $i=$int($request.field('c', 0))
> <p>Try: $i</p>
> #if 0 < $i <$counter:
>     <a href='http://${request.serverURL()}?c=${i+1}'>next</a>
> #else
>     <a href='http://${request.serverURL()}?c=1'>next</a>
> #end if
> 
> 
> testpsp.psp:
> ==========
> <%
> counter = 100
> i=int(req.field('c', 0))
> res.write("<p>Try: %d</p>" % i)
> if 0 < i <counter:
>     res.write("<a href='http://%s?c=%d'>next</a>" % (req.serverURL(),
> i+1))
> else: 
>     res.write("<a href='http://%s?c=1'>next</a>" % req.serverURL())
> %>
> 
> testspyce.spy
> ==========
> <%\
> counter = 100
> i =request.get1('c', 0)
> %>
> <p>Try: <%=i%></p>
> <%if 0 < i < counter:{%>
>     <%i += 1%>
>     <a
> href='http://localhost<%=request.uri("path")%>?c=<%=i%>'>next</a>
> <%} else: {%>
>     <a href='http://localhost<%=request.uri("path")%>?c=1'>next</a>
> <%}%>
> 
> testphp.php:
> ==========
> <?php
> $counter = 100;
> $i =$_GET['c'] ? $_GET['c'] : 0;
> echo "<p>Try: $i</p>";
> if ($i > 0 and $i < $counter) {
>     $i += 1;
>     echo "<a
> href='http://{$_SERVER['SERVER_NAME']}{$_SERVER['PHP_SELF']}?c=$i'>next</a>";
> } else {
>     echo "<a
> href='http://{$_SERVER['SERVER_NAME']}{$_SERVER['PHP_SELF']}?c=1'>next</a>";
> }
> ?>
> 
> 
> RESULTS:
> =========
> 
> Webware servlet without templates:
> >>>http://localhost/WK/test/test1/testpython.py  => time: 20.078000 s
> 
> Webware servlet with its PSP templates
> >>>http://localhost/WK/test/test1/testpsp.psp  => time: 20.015000 s
> 
> Webware with Cheetah template/servlet:
> >>>http://localhost/WK/test/test1/testcheetah.tmpl  => time: 20.235000 s
> 
> Webware with Cheetah servlet (compiled with cheetah-compile script):
> >>>http://localhost/WK/test/test1/testcheetah.py  => time: 20.250000 s
> 
> PHP with mod_php4 and MMCache free accelerator
> >>>http://localhost/testphp.php  => time: 3.891000 s [mcache & mod_php4]
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> PHP as CGI
> >>>http://localhost/testphp.php  => time: 15.094000 s
> 
> Spyce as CGI:
> >>>http://localhost/testspyce.spy  => time: 53.672000 s
> (I coud not test Spyce and mod_python because mod_python 3.0.3 does
> not work with Python 2.3.2)
> 
> What you think about it? PHP with MMCache accelerator is about 6x
> faster than teh fastest Python! I like Python but I am very
> disappointed its performance!!! :-((((( The difference is so huge,
> that I think about rewriting my Python code back to PHP....
> 
> Links:
> 
> Python http://www.python.org/
> Webware http://webware.sourceforge.net/
> Cheetah http://www.cheetahtemplate.org/
> Spyce http://spyce.sourceforge.net/
> 
> PHP http://www.php.net/
> MMCache http://turck-mmcache.sourceforge.net/




More information about the Python-list mailing list