Skip to content

Instantly share code, notes, and snippets.

@svetlyak40wt
Created September 14, 2020 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svetlyak40wt/8e92545f419d2ba9821d3a936a464461 to your computer and use it in GitHub Desktop.
Save svetlyak40wt/8e92545f419d2ba9821d3a936a464461 to your computer and use it in GitHub Desktop.
Test for Jinja2 performance on Python2.7
# Test for this post:
# https://40ants.com/lisp-project-of-the-day/2020/09/0188-zenekindarl.html
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