-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbench.py
39 lines (30 loc) · 1.49 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
# -*- coding: utf-8 -*-
"""I (mklein) have no idea how to write benchmarks in python. These benchmarks are highly
doubtful!!!"""
LOREMIPSUM = """Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod\
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud\
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in\
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint\
occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.""".encode(
"utf-8"
)
import urlquote
from urllib.parse import quote as urllib_quote
import timeit
def benchmark_quote_urlquote():
urlquote.quote(LOREMIPSUM, urlquote.quoting.PYTHON_3_7_QUOTING)
def benchmark_quote_urllib():
urllib_quote(LOREMIPSUM)
if __name__ == "__main__":
print("This library")
setup = "from __main__ import benchmark_quote_urlquote"
expression = "benchmark_quote_urlquote()"
repetitions = 100000
duration = timeit.timeit(expression, setup=setup, number=repetitions)
print("Total duration: ", duration, "Average Duration: ", duration / repetitions)
print("Urllib")
setup = "from __main__ import benchmark_quote_urllib"
expression = "benchmark_quote_urllib()"
repetitions = 100000
duration = timeit.timeit(expression, setup=setup, number=repetitions)
print("Total duration: ", duration, "Average Duration: ", duration / repetitions)