Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Test for Jinja2 performance on Python2.7
# Test for this post:
Python 2.7.16 (default, Apr 17 2020, 18:29:03)
Type "copyright", "credits" or "license" for more information.
IPython 5.10.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: from jinja2 import Template
In [2]: template = Template("""
...: <h1>{{ title }}</h1>
...: <ul>
...: {% for item in items %}
...: <li>{{ item }}</li>
...: {% endfor %}
...: </ul>
...: """)
In [3]: %timeit template.render(title='Foo Bar', items=['One', 'Two', 'Tree'])
The slowest run took 5.56 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 6.48 µs per loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment