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">
<!-- 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 -->
<!-- Same for body section -->
If you enjoyed this post, make sure you subscribe to my RSS feed!