Skip to content

Commit 91a641e

Browse files
authored
Add benchmark script (#61)
1 parent 3d6836b commit 91a641e

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

benchmark.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from os.path import dirname, join
2+
from json import load
3+
from urllib.parse import urlparse
4+
from time import perf_counter
5+
6+
from ada_url import URL
7+
8+
URL_TEST_DATA_PATH = join(dirname(__file__), 'tests/files/urltestdata.json')
9+
10+
with open(URL_TEST_DATA_PATH, 'rb') as f:
11+
test_data = load(f)
12+
13+
test_cases = []
14+
for item in test_data:
15+
if isinstance(item, str) or item.get('failure', False):
16+
continue
17+
test_cases.append(item['href'])
18+
19+
print('Function', 'msec', 'URLs/msec', sep='\t')
20+
for func_name, func in (('stdlib urlparse', urlparse), ('ada_url URL', URL)):
21+
start_time = perf_counter()
22+
for item in test_cases:
23+
func(item)
24+
duration = perf_counter() - start_time
25+
rate = len(test_cases) / duration
26+
print(func_name, f'{duration * 1000:0.2f}', f'{rate / 1000:0.2f}', sep='\t')

0 commit comments

Comments
 (0)