Skip to content

Instantly share code, notes, and snippets.

@bootandy
Created November 6, 2014 00:09
Show Gist options
  • Save bootandy/432315fa690c7c1b5c35 to your computer and use it in GitHub Desktop.
Save bootandy/432315fa690c7c1b5c35 to your computer and use it in GitHub Desktop.
How 2 line_profiler test a jinja2 template
import os
from jinja2 import Environment, FileSystemLoader
from line_profiler import LineProfiler
@profile
def render_template(template_filename, context):
return TEMPLATE_ENVIRONMENT.get_template(template_filename).render(context)
PATH = os.path.dirname(os.path.abspath(__file__))
TEMPLATE_ENVIRONMENT = Environment(loader=FileSystemLoader(os.path.join(PATH, '')))
file = "out.jinja2"
context = {'urls': ['a.com']}
for i in range(0, 1000):
out = render_template(file, context)
#print(out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment