• Could not connect to Twitter

Speed-testing Genshi pages for optimisation

To optimise some of our slower Genshi pages (e.g. this one) I needed a reliable way of extracting render-times from different sections of the templates. Python’s datetime module came to the rescue.

Below is a snippet of a Genshi template showing how I embedded calls to datetime and how I rendered the time-differences in the resulting page.

This is a quick and hacky solution, useful for noting performance numbers (I used 4 refreshes of each page to get average values). Once I was finished with my optimisations I just deleted the datetime code.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"

<!-- Bring datetime into our Python namespace -->
<?python import datetime ?>
<!-- Put the current time into t1 -->

<?python t1=datetime.datetime.now() ?>
...<!-- imports I want to speed-test -->
<?python t2=datetime.datetime.now() ?>

...<!-- main body of the template -->

<?python t3=datetime.datetime.now() ?>
<!-- Show in the rendered page the time spent in the imports section -->
<p>${"imports ",t2-t1}</p>
<!-- Same for body section -->

<p>${"body ",t3-t2}</p>


Please share:
  • DZone
  • del.icio.us
  • Reddit
  • Furl
  • Ma.gnolia
  • email
  • StumbleUpon
  • Technorati
  • TwitThis
  • Slashdot
If you enjoyed this post, make sure you subscribe to my RSS feed!

Related posts:

  1. Optimising Genshi Imports
  2. Productive in 10 minutes with TurboGears and Python 2.5
  3. New Python ShowMeDos: Web Testing with PAMIE
  4. 5 Minutes with Python @ python.org
  5. Testing Flowplayer embedding script

2 comments to Speed-testing Genshi pages for optimisation

  • [...] ShowMeDo Blog ShowMeDo News and Thoughts « Speed-testing Genshi pages for optimisation [...]

  • Genshi is certainly faster than Kid (and much faster in some of the corner cases that Kid didn’t handle well). Cheetah is definitely faster than Genshi, and there’s really no way that an XML template language can be as fast as a plain text driven template language, because it has to understand what it’s reading somewhat rather than just spewing text.

    I haven’t used Kid in quite some time myself.