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.
| Engine | Time | Quoting | Version | Remark |
|---|---|---|---|---|
| qpy | 0.86 ms | automatic | 1.6 | automatic safe quoting, h8 |
| evoque | 2.50 ms | automatic | ||
| evoque_mq | 2.26 ms | manual | manual quoting, no qpy | |
| evoque_r | 3.09 ms | automatic | restricted execution | |
| mako | 2.73 ms | manual | 0.1.10 | |
| genshi_text | 6.54 ms | manual | 0.4.4 | |
| genshi | 15.03 ms | automatic | 0.4.4 | xml mode |
bigtable
A simple brute force generation of a 10 columns x 1000 rows table. Time is averaged over 10 renderings.
| Engine | Time | Quoting | Version | Remark |
|---|---|---|---|---|
| qpy | 260.58 ms | automatic | 1.6 | automatic safe quoting, h8 |
| evoque | 487.00 ms | automatic | ||
| evoque_mq | 409.71 ms | manual | manual quoting, no qpy | |
| evoque_r | 616.83 ms | automatic | restricted execution | |
| mako | 445.47 ms | manual | 0.1.10 | |
| genshi | 1747.29 ms | automatic | 0.4.4 | xml 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.
| Engine | Time | Quoting | Version | Remark |
|---|---|---|---|---|
| pystr | 0.29 ms | - | 2.5.1 | string.Template, no quoting |
| qpy | 0.21 ms | automatic | 1.6 | automatic safe quoting, h8 |
| evoque | 0.24 ms | automatic | ||
| evoque_mq | 0.27 ms | manual | manual quoting, no qpy | |
| evoque_r | 0.31 ms | automatic | restricted execution | |
| mako | 0.72 ms | manual | 0.1.10 | |
| genshi_text | 1.32 ms | manual | 0.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.
Del.icio.us