forked from aio-libs/yarl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.py
52 lines (33 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
import timeit
cython_setup = """\
from yarl.quoting import _Quoter as Quoter
from yarl.quoting import _Unquoter as Unquoter
"""
python_setup = """\
from yarl.quoting import _PyQuoter as Quoter
from yarl.quoting import _PyUnquoter 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()")))