-
-
Notifications
You must be signed in to change notification settings - Fork 164
/
benchmark.py
67 lines (49 loc) · 1.31 KB
/
benchmark.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import timeit
cython_setup = """\
from yarl._quoting_c import _Quoter as Quoter
from yarl._quoting_c import _Unquoter as Unquoter
"""
python_setup = """\
from yarl._quoting_py import _Quoter as Quoter
from yarl._quoting_py import _Unquoter as Unquoter
"""
print(
"Cython quote ascii: {:.3f} sec".format(
timeit.timeit("q(s)", cython_setup + "s='/path/to';q=Quoter(safe='/')")
)
)
print(
"Python quote ascii: {:.3f} sec".format(
timeit.timeit("q(s)", python_setup + "s='/path/to';q=Quoter(safe='/')")
)
)
print(
"Cython quote PCT: {:.3f} sec".format(
timeit.timeit("q(s)", cython_setup + "s='abc%0a';q=Quoter()")
)
)
print(
"Python quote PCT: {:.3f} sec".format(
timeit.timeit("q(s)", python_setup + "s='abc%0a';q=Quoter()")
)
)
print(
"Cython quote: {:.3f} sec".format(
timeit.timeit("q(s)", cython_setup + "s='/шлях/файл';q=Quoter()")
)
)
print(
"Python quote: {:.3f} sec".format(
timeit.timeit("q(s)", python_setup + "s='/шлях/файл';q=Quoter()")
)
)
print(
"Cython unquote: {:.3f} sec".format(
timeit.timeit("u(s)", cython_setup + "s='/path/to';u=Unquoter()")
)
)
print(
"Python unquote: {:.3f} sec".format(
timeit.timeit("u(s)", python_setup + "s='/path/to';u=Unquoter()")
)
)