Add benchmarks
anonrig opened this issue · 4 comments
How does ada-python perform compared to urllib?
Last time I ran simplistic benchmarks, we were 50% slower than urllib.
#1 (comment)
@TkTech had a faster alternative which we did not take.
It is possible that the current version fares better.
It is likely that most of the running time will be spent on the binding and not in ada per se.
I can update my version if you'd find it useful for comparison.
I updated the script from the earlier comment.
import can_ada
from urllib.parse import urlparse
from ada_url import URL
from time import perf_counter
import os
print("can_ada")
start_time = perf_counter()
total = 0
with open('/tmp/top100.txt', 'rt') as f:
for line in f:
try:
can_ada.parse(line)
except Exception:
pass
else:
total +=1
end_time = perf_counter()
print(total, end_time - start_time, sep='\t')
print("urllib")
start_time = perf_counter()
total = 0
with open('/tmp/top100.txt', 'rt') as f:
for line in f:
try:
urlparse(line)
except Exception:
pass
else:
total +=1
end_time = perf_counter()
print(total, end_time - start_time, sep='\t')
print("ada_url")
start_time = perf_counter()
total = 0
with open('/tmp/top100.txt', 'rt') as f:
for line in f:
try:
urlobj = URL(line)
except ValueError:
pass
else:
total +=1
end_time = perf_counter()
print(total, end_time - start_time, sep='\t')Here are the results I got:
can_ada
99999 0.1501040810253471
urllib
100031 0.5046708540758118
ada_url
99999 0.2472913929959759
Not slower than urllib after the changes I made re: the last thread.
A new v1.1.1 version of can_ada is live with the latest upstream Ada, py312 binaries, and idna_encode/idna_decode for parity with ada_url.
No change to the general performance, which makes sense since the benchmark in this thread is mostly just testing function call overhead when comparing the two.
If your goal is performance at all costs, a quick minimal C-only wrapper was even faster, but comes at the cost of drastically more work in the bindings then the ~60 lines they are currently. Wouldn't recommend it for dev sanity.