File: bigbench.py

package info (click to toggle)
jinja 1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 1,408 kB
  • ctags: 1,171
  • sloc: python: 6,438; ansic: 397; makefile: 74
file content (88 lines) | stat: -rw-r--r-- 1,650 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import jdebug
from time import time
from jinja import Environment
tmpl = Environment().from_string('''
<h1>Bigtable</h1>
<table>
{%- for row in table -%}
  <tr>
  {%- for col in row.values() %}
    <td>{{ col }}</td>
  {%- endfor %}
  </tr>
{%- endfor %}
</table>

<h1>Unfilled</h1>
<div class="index">
  {%- for column in items|slice(3) %}
  <div class="col-{{ loop.index }}">
    <ul>
    {%- for item in column %}
      <li>{{ item }}</li>
    {%- endfor %}
    </ul>
  </div>
  {%- endfor %}
</div>

<h1>Filled</h1>
<div class="index">
  {%- for column in items|slice(3, 'missing') %}
  <div class="col-{{ loop.index }}">
    <ul>
    {%- for item in column %}
      <li>{{ item }}</li>
    {%- endfor %}
    </ul>
  </div>
  {%- endfor %}
</div>

<h1>Filled Table</h1>
<table>
  {%- for row in items|batch(3, '&nbsp;') %}
  <tr>
    {%- for column in row %}
    <td>{{ column }}</td>
    {%- endfor %}
  </tr>
  {%- endfor %}
</table>

<h1>Unfilled Table</h1>
<table>
  {%- for row in items|batch(3) %}
  <tr>
    {%- for column in row %}
    <td>{{ column }}</td>
    {%- endfor %}
    {%- if row|length < 3 %}
    <td colspan="{{ 3 - (row|length) }}">&nbsp;</td>
    {%- endif %}
  </tr>
  {%- endfor %}
</table>

<h1>Macros</h1>
{% macro foo seq %}
  <ul>
  {%- for item in seq %}
    <li>{{ caller(item=item) }}</li>
  {%- endfor %}
  </ul>
{% endmacro %}

{% call foo(items) -%}
  [{{ item }}]
{%- endcall %}
''')

start = time()
for _ in xrange(50):
    tmpl.render(
        items=range(200),
        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)]
    )
print time() - start