-
Notifications
You must be signed in to change notification settings - Fork 0
/
jinja_speed.py
46 lines (34 loc) · 1.1 KB
/
jinja_speed.py
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
# coding: utf-8
from jinja2 import Template
with open('template.html') as f:
jinja_template = Template(f.read())
def jinja_index():
user = {
'username': 'art',
'contacts': [
{'type': 'email',
'value': '[email protected]'},
]
}
title = 'User Profile'
return jinja_template.render(user=user, title=title)
# CPython
# In [10]: %timeit jinja_index()
# The slowest run took 5.19 times longer than the fastest. This could mean that an intermediate result is being cached.
# 100000 loops, best of 3: 19.5 µs per loops
# PyPy
# In [11]: %timeit jinja_index()
# The slowest run took 24.93 times longer than the fastest. This could mean that an intermediate result is being cached.
# 100000 loops, best of 3: 3.64 µs per loop
user = {
'username': 'art',
'contacts': [
{'type': 'email',
'value': '[email protected]'},
]
}
title = 'User Profile'
def jinja_index2(user, title):
return jinja_template.render(user=user, title=title)
# In [9]: %timeit jinja_index2(user, title)
# 100000 loops, best of 3: 17.5 µs per loop