-
Notifications
You must be signed in to change notification settings - Fork 65
/
bench.py
51 lines (49 loc) · 1.04 KB
/
bench.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
47
48
49
50
51
import cProfile
import pstats
from io import StringIO
from tempy.tags import Table, Tr, Td, Div
from tempy.widgets import TempyPage
TABLE_DATA = [
dict(a='a',
b='b',
c='c',
d='d',
e='e',
f='f',
g='g',
h='h',
i='i',
j='k') for x in range(100)
]
page = TempyPage()
pr = cProfile.Profile()
pr.enable()
for _ in range(100):
page.body(
Div()(
table=Table()(
Tr(id='%s' % i)(
Td(klass='CIAO', id='%s-%s' % (i, td))(cont=td) for td in tr.values()
) for i, tr in enumerate(TABLE_DATA)
)
)
)
pr.disable()
s = StringIO()
sortby = 'tottime'
ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
print('*' * 200)
print('CREATION')
ps.print_stats()
print(s.getvalue())
pr = cProfile.Profile()
pr.enable()
_ = page.render()
pr.disable()
s = StringIO()
sortby = 'tottime'
ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
print('*' * 200)
print('RENDERING')
ps.print_stats()
print(s.getvalue())