Skip to content
Myr

profile.py

This file

Path

examples/profile.py

49 lines · 1.0 KiB · Python

Last changed by

added a function to parse assign targes and documented it for the extension interfaceArmin Ronacherbefore adoption09c002e

History of this file

Take it

1try:2    from cProfile import Profile3except ImportError:4    from profile import Profile5from pstats import Stats6from jinja2 import Environment as JinjaEnvironment78context = {9    'page_title': 'mitsuhiko\'s benchmark',10    'table': [dict(a=1,b=2,c=3,d=4,e=5,f=6,g=7,h=8,i=9,j=10) for x in range(1000)]11}1213source = """\14<!doctype html>15<html>16  <head>17    <title>${page_title|e}</title>18  </head>19  <body>20    <div class="header">21      <h1>${page_title|e}</h1>22    </div>23    <div class="table">24      <table>25      % for row in table26        <tr>27        % for cell in row28          <td>${cell}</td>29        % endfor30        </tr>31      % endfor32      </table>33    </div>34  </body>35</html>\36"""37jinja_template = JinjaEnvironment(38    line_statement_prefix='%',39    variable_start_string="${",40    variable_end_string="}"41).from_string(source)42print jinja_template.environment.compile(source, raw=True)434445p = Profile()46p.runcall(lambda: jinja_template.render(context))47stats = Stats(p)48stats.sort_stats('time', 'calls')49stats.print_stats()