-
Notifications
You must be signed in to change notification settings - Fork 16
/
speedtest.py
executable file
·48 lines (39 loc) · 1.38 KB
/
speedtest.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
#!/usr/bin/env -S hatch env run -e speedtest python
# ruff: noqa: T201
import time
from collections import defaultdict
from contextlib import contextmanager
from genshi.template import MarkupTemplate
from kajiki import XMLTemplate
FN = "tests/data/tables.html"
timings = defaultdict(float)
@contextmanager
def timing(s):
start = time.time()
yield
elapsed = time.time() - start
print(f"{s}: {elapsed} s")
timings[s] += elapsed
with timing("compile.kajiki"):
fpt = XMLTemplate(filename=FN)
with timing("compile.genshi"), open(FN) as f:
gt = MarkupTemplate(f)
with timing("render.100.kajiki"):
fpt({"size": 100}).render()
with timing("render.100.genshi"):
gt.generate(size=100).render()
with timing("render.100.kajiki"):
fpt({"size": 100}).render()
with timing("render.100.genshi"):
gt.generate(size=100).render()
with timing("render.100.kajiki"):
fpt({"size": 100}).render()
with timing("render.100.genshi"):
gt.generate(size=100).render()
with timing("render.500.kajiki"):
fpt({"size": 500}).render()
with timing("render.500.genshi"):
gt.generate(size=500).render()
print("Compile kajiki speedup:", timings["compile.genshi"] / timings["compile.kajiki"])
print("Render 100 kajiki speedup:", timings["render.100.genshi"] / timings["render.100.kajiki"])
print("Render 500 kajiki speedup:", timings["render.500.genshi"] / timings["render.500.kajiki"])