Skip to content

Add benchmark script #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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')