Source

mako_v_jinja / run.py

Full commit
from jinja2 import Environment, FileSystemLoader, __version__ as jinja_version
jinja_env = Environment(loader=FileSystemLoader('./jinja2'))

from mako.lookup import TemplateLookup
from mako import __version__ as mako_version

mako_env = TemplateLookup('./mako')

mako_def_env = TemplateLookup('./mako_def')

import timeit

environment = dict(("key_%d" % i, "value_%d" % i) for i in xrange(50))

def jinja2():
    template = jinja_env.get_template('hello.jinja2')
    val = template.render(environment=environment)
    return val
    
def mako():
    template = mako_env.get_template("hello.mako")
    val = template.render(environment=environment)
    return val

def mako_def():
    template = mako_def_env.get_template("hello.mako")
    val = template.render(environment=environment)
    return val

# content is identical
assert jinja2() == mako()
assert jinja2() == mako_def() 

print "jinja2 %s:" % jinja_version, timeit.timeit(
                                        "jinja2()", 
                                        "from __main__ import jinja2", 
                                        number=10000)
                                        
print "mako %s:" % mako_version, timeit.timeit(
                                        "mako()", 
                                        "from __main__ import mako", 
                                        number=10000)

print "mako %s using def:" % mako_version, timeit.timeit(
                                        "mako_def()", 
                                        "from __main__ import mako_def", 
                                        number=10000)