-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbenchmark.py
More file actions
26 lines (21 loc) · 812 Bytes
/
benchmark.py
File metadata and controls
26 lines (21 loc) · 812 Bytes
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
from os.path import dirname, join
from json import load
from urllib.parse import urlparse
from time import perf_counter
from ada_url import URL
URL_TEST_DATA_PATH = join(dirname(__file__), 'tests/files/urltestdata.json')
with open(URL_TEST_DATA_PATH, 'rb') as f:
test_data = load(f)
test_cases = []
for item in test_data:
if isinstance(item, str) or item.get('failure', False):
continue
test_cases.append(item['href'])
print('Function', 'msec', 'URLs/msec', sep='\t')
for func_name, func in (('stdlib urlparse', urlparse), ('ada_url URL', URL)):
start_time = perf_counter()
for item in test_cases:
func(item)
duration = perf_counter() - start_time
rate = len(test_cases) / duration
print(func_name, f'{duration * 1000:0.2f}', f'{rate / 1000:0.2f}', sep='\t')