profile.py
This file
Path
examples/profile.py
52 lines · 1.1 KiB · Python
Last changed by
Not known.
History of this fileTake 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% macro testmacro(x)15 <span>${x}</span>16% endmacro17<!doctype html>18<html>19 <head>20 <title>${page_title|e}</title>21 </head>22 <body>23 <div class="header">24 <h1>${page_title|e}</h1>25 </div>26 <div class="table">27 <table>28 % for row in table29 <tr>30 % for cell in row31 <td>${testmacro(cell)}</td>32 % endfor33 </tr>34 % endfor35 </table>36 </div>37 </body>38</html>\39"""40jinja_template = JinjaEnvironment(41 line_statement_prefix='%',42 variable_start_string="${",43 variable_end_string="}"44).from_string(source)45print jinja_template.environment.compile(source, raw=True)464748p = Profile()49p.runcall(lambda: jinja_template.render(context))50stats = Stats(p)51stats.sort_stats('time', 'calls')52stats.print_stats()