forked from pallets/markupsafe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench.py
30 lines (29 loc) · 927 Bytes
/
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
import subprocess
import sys
for name, s in (
("short escape", '"<strong>Hello, World!</strong>"'),
("long escape", '"Hello, World!" * 1000'),
("short plain", '"Hello, World!"'),
("long plain", '"Hello, World!" * 1000'),
("long suffix", '"<strong>Hello, World!</strong>" + "x" * 100_000'),
):
for mod in "native", "speedups":
subprocess.run(
[
sys.executable,
"-m",
"pyperf",
"timeit",
"--name",
f"{name} {mod}",
"-s",
(
"import markupsafe\n"
f"from markupsafe._{mod} import _escape_inner\n"
"markupsafe._escape_inner = _escape_inner\n"
"from markupsafe import escape\n"
f"s = {s}"
),
"escape(s)",
]
)