blob: a154404c259a1e95ac6d6b4fc95d51723c739dcc [file] [log] [blame]
Armin Ronacher612b3a82008-05-07 15:39:39 +02001try:
2 from cProfile import Profile
3except ImportError:
4 from profile import Profile
5from pstats import Stats
6from jinja2 import Environment as JinjaEnvironment
7
8context = {
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}
12
Armin Ronacher09c002e2008-05-10 22:21:30 +020013source = """\
Armin Ronacher612b3a82008-05-07 15:39:39 +020014<!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>
Armin Ronacher612b3a82008-05-07 15:39:39 +020023 <div class="table">
24 <table>
25 % for row in table
26 <tr>
27 % for cell in row
28 <td>${cell}</td>
29 % endfor
30 </tr>
31 % endfor
32 </table>
33 </div>
34 </body>
35</html>\
Armin Ronacher09c002e2008-05-10 22:21:30 +020036"""
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)
Armin Ronacher612b3a82008-05-07 15:39:39 +020043
44
45p = Profile()
46p.runcall(lambda: jinja_template.render(context))
47stats = Stats(p)
48stats.sort_stats('time', 'calls')
49stats.print_stats()