Performance benchmark

Some benchmarks, inspired from the basic and bigtable bechmarks proposed by Genshi. All are included in the distribution -- please try out for yourself.

Please remember that performance benchmarks are only relevant when considered within an entire context, and they may vary enormously between one environment and another. In addition, no two systems ever do precisely the same thing, however simple and apparently identical the timed task may be.

benchmarks

The actual times below are coming off an old OS X 10.3 667 MHz G4 PowerBook, running python 2.5.1. What you should want is automatic quoting and less time.

basic

A small template, doing a variety of standard templating tasks such as looping, calling sub-templates, escaping of data, etc. Time is averaged over 2000 renderings.

EngineTimeQuotingVersionRemark
qpy0.86 msautomatic1.6automatic safe quoting, h8
evoque2.50 msautomatic
evoque_mq2.26 msmanualmanual quoting, no qpy
evoque_r3.09 msautomaticrestricted execution
mako2.73 msmanual0.1.10
genshi_text6.54 msmanual0.4.4
genshi15.03 msautomatic0.4.4xml mode

bigtable

A simple brute force generation of a 10 columns x 1000 rows table. Time is averaged over 10 renderings.

EngineTimeQuotingVersionRemark
qpy260.58 msautomatic1.6automatic safe quoting, h8
evoque487.00 msautomatic
evoque_mq409.71 msmanualmanual quoting, no qpy
evoque_r616.83 msautomaticrestricted execution
mako445.47 msmanual0.1.10
genshi1747.29 msautomatic0.4.4xml mode

subs

For curiosity, here's a performance look at doing only string substitutions -- thus for this one we can even compare against string.Template from the python standard library. We test a small template, mostly static text with just 6 variable substitutions. Time is averaged over 2000 renderings.

EngineTimeQuotingVersionRemark
pystr0.29 ms-2.5.1string.Template, no quoting
qpy0.21 msautomatic1.6automatic safe quoting, h8
evoque0.24 msautomatic
evoque_mq0.27 msmanualmanual quoting, no qpy
evoque_r0.31 msautomaticrestricted execution
mako0.72 msmanual0.1.10
genshi_text1.32 msmanual0.4.4

Remarks

Qpy is a templating system almost identical to straight python and offering convenient and fast (at least the C based version) html string building with automatic escaping. From the Qpy readme: Qpy provides a convenient mechanism for generating safely-quoted html text from python code. It does this by implementing a quoted-string data type and a modification of the python compiler.

Amongst currently popular full-featured templating systems for python: Mako is probably the fastest pure-python text-based system; Genshi is probably the feature-richest XML-based system.

The performance of the Evoque and Mako text-based systems seems to be more or less similar. Evoque seems to be faster for very simple templates, while Mako seems to be quicker on loop-intensive templates -- probably because of additional work that Evoque has to do for the runtime evaluation of loop variables.

A little experimentation on another platform (Ubuntu on a 2.0GHz Intel Celeron) indicates that Qpy and pystr are compartively significantly faster than on the OS X G4 where these numbers were gathered. The speed ratio amongst the others seems to more or less stay the same.

A straight comparison may be misleading. Automatic quoting necessarily incurs more overhead than manual quoting, so it would seem to make more sense to compare mako or genshi_text with evoque_mq rather than with evoque.

Suggestions to make these benchmarks more relevant are welcome, especially from anyone with particular knowledge of the specific templating system in question.

The numbers from these benchmarks are a tribute to python's conceptual integrity -- that rewards a straightforward implementation of a simple design with... amazing performance.