Performance
  1. Simple Benchmark
  2. Compared to Other Engines

Simple Benchmark

Here's an extremely simple benchmark to give an idea of Brevé's performance.

Here's our simple template:

# template.b

html [
    head [
        title [ 'breve benchmark' ]
    ],

    body [
        div [
            span [ 'this is a test' ]
        ]
    ]
]

And the test program:

# run.py

from breve import Template
from breve.tags import html
from timeit import Timer

root = ''
template = 'template'
vars = { }
iterations = 100000

def test ( ):
    t = Template ( html.tags, root = root, doctype = html.doctype, xmlns = html.xmlns )
    t.render ( template = template, vars = vars )

if __name__== '__main__':
    t = Timer ( "test()", "gc.enable(); from __main__ import test" )
    seconds = t.timeit ( iterations )
    print "time for %d iterations:" % iterations, seconds, "(%f pages/s)" % ( iterations / seconds )

And finally, the results:

$ time python run.py
time for 100000 iterations: 26.6540670395 (3751.772660 pages/s)

real    0m26.883s
user    0m26.105s
sys     0m0.694s

Out of curiosity, I decided to also give Psyco a try, so I added

import psyco
psyco.full()

to the top of run.py. This gave the following:

$ time python run.py
time for 100000 iterations: 21.9135439396 (4563.387842 pages/s)

real    0m22.263s
user    0m21.496s
sys     0m0.679s

Tests were done on a 1.7GHz Centrino laptop w/ 1GB of RAM running Fedora Core 6 (kernel 2.6.19), Python 2.4.4 and Brevé 1.1.5.

Compared to Other Engines

The Genshi site has the closest thing I've ever seen to a standard Python template engine benchmark, so I added a Brevé section and got these results (on the same system as above):

Genshi template + tag builder                 968.39 ms
Genshi tag builder                            875.93 ms
Genshi template                               842.00 ms
Kid template                                  933.49 ms
Kid template + cElementTree                   880.02 ms
Django template                               554.45 ms
ElementTree                                   445.08 ms
Brevé                                         307.43 ms
cElementTree                                  271.75 ms
Myghty Template                               114.16 ms

Again, I ran the same tests with psyco.full(). Oddly Genshi and Kid got slower, which I find inexplicable:

Genshi template + tag builder                1069.55 ms
Kid template                                 1045.82 ms
Kid template + cElementTree                  1011.24 ms
Genshi template                               987.57 ms
Genshi tag builder                            942.84 ms
Django template                               418.49 ms
ElementTree                                   317.49 ms
Brevé                                         219.45 ms
cElementTree                                  130.96 ms
Myghty Template                                40.15 ms

Myghty appears insanely fast in this benchmark. I expect this is because it doesn't deal with individual elements like the other engines, rather just strings and thus cuts its processing time per table row substantially. I also don't think it does any escaping of content or attributes. Brevé escapes everything by default.

The second benchmark gave somewhat different results:

Kid:    6.35 ms
Genshi: 5.85 ms
Django: 1.89 ms
Myghty: 1.87 ms
Brevé:  0.82 ms

From what I can see looking at the different templates utilized in these tests, it's abundantly clear why we have so many different template engines in the Python world: all of them are pretty unique in approach and features. Performance is undoubtedly heavily dependent on application and, most likely, performance will be the least of a developer's concerns when selecting which engine to use. Nevertheless these tests at least affirm my suspicion that Brevé scores near the top of the class in this category.

edit page
Back to top
Rendered using Brevé 1.2.6Copyright © 2007, Cliff Wells