Fastest pure python text-based templating?
Mako is a mature full-featured templating engine for python. It is also pure-python i.e. it has no C-compiled extensions, and amongst pure-python systems it is currently considered to be the fastest.
Evoque is a new lightweight templating engine for python, also pure-python and full-featured. Its simple implementation is based on the eval python builtin, and weighs in at less than 1K lines of code, compared to about 2.5K for Mako, or about 4K for Genshi. One of Evoque's distinguishing features is automatic input quoting that, to my knowledge, Mako does not do, at least not by default.
It is difficult to make sensical performance comparisons between systems -- never do such comparisons give the entire picture. I will try to highlight the specific performance results for Evoque in manual quoting mode (called evoque_mq when used this way) and those for Mako -- two systems that come close to being equivalent. The Evoque distribution contains the following three benchmarks:
OS X 10.3 on a 667 MHz G4 PowerBook
Evoque is a new lightweight templating engine for python, also pure-python and full-featured. Its simple implementation is based on the eval python builtin, and weighs in at less than 1K lines of code, compared to about 2.5K for Mako, or about 4K for Genshi. One of Evoque's distinguishing features is automatic input quoting that, to my knowledge, Mako does not do, at least not by default.
It is difficult to make sensical performance comparisons between systems -- never do such comparisons give the entire picture. I will try to highlight the specific performance results for Evoque in manual quoting mode (called evoque_mq when used this way) and those for Mako -- two systems that come close to being equivalent. The Evoque distribution contains the following three benchmarks:
- subs - does only string substitutions
- basic - does a variety of standard templating tasks such as looping, calling sub-templates, escaping of data
- bigtable - a simple brute force generation of a 10 columns x 1000 rows table
OS X 10.3 on a 667 MHz G4 PowerBook
subs basic bigtableUbuntu 7.04 on a 2.0 GHz Intel Celeron
evoque_mq 0.27 2.26 409.71
mako 0.72 2.73 445.47
subs basic bigtableEvoque is not always faster. It seems to be consistently faster for simpler templates, while Mako seems to be quicker on loop-intensive templates, such as the 1000 row table benchmark. This is probably because of additional work that Evoque has to do for the runtime evaluation of loop variables.
evoque_mq 0.13 1.25 152.12
mako 0.38 1.28 142.53
Labels: benchmark, evoque, mako, python, templating