blob: 0c907ae3f12a64e21087a9a591b1407b780b1bb1 [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 Ronacherf60232d2010-06-05 14:31:27 +020014% macro testmacro(x)
Armin Ronacher850629f2010-06-06 15:14:55 +020015 <span>${x}</span>
Armin Ronacherf60232d2010-06-05 14:31:27 +020016% endmacro
Armin Ronacher612b3a82008-05-07 15:39:39 +020017<!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>
Armin Ronacher612b3a82008-05-07 15:39:39 +020026 <div class="table">
27 <table>
28 % for row in table
29 <tr>
30 % for cell in row
Armin Ronacherf60232d2010-06-05 14:31:27 +020031 <td>${testmacro(cell)}</td>
Armin Ronacher612b3a82008-05-07 15:39:39 +020032 % endfor
33 </tr>
34 % endfor
35 </table>
36 </div>
37 </body>
38</html>\
Armin Ronacher09c002e2008-05-10 22:21:30 +020039"""
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)
Armin Ronacher612b3a82008-05-07 15:39:39 +020046
47
48p = Profile()
49p.runcall(lambda: jinja_template.render(context))
50stats = Stats(p)
51stats.sort_stats('time', 'calls')
52stats.print_stats()