Skip to content
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

Improve performance of building unencoded URLs #1188

Merged
merged 13 commits into from
Oct 11, 2024
81 changes: 81 additions & 0 deletions url_benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import timeit

from yarl import URL

bdraco marked this conversation as resolved.
Show resolved Hide resolved
print(
"Build URL with host and path and port: {:.3f} sec".format(
timeit.timeit(
"URL.build(host='localhost', path='/req', port=1234)",
globals={"URL": URL},
number=100000,
)
)
)

print(
"Build URL with host: {:.3f} sec".format(
timeit.timeit(
"URL.build(host='localhost')", globals={"URL": URL}, number=100000
)
)
)

print(
"Build URL with host and port: {:.3f} sec".format(
timeit.timeit(
"URL.build(host='localhost', port=1234)",
globals={"URL": URL},
number=100000,
)
)
)

print(
"Make URL with host and path and port: {:.3f} sec".format(
timeit.timeit(
"URL('http://localhost:1234/req')", globals={"URL": URL}, number=100000
)
)
)

print(
"Make URL with host and path: {:.3f} sec".format(
timeit.timeit(
"URL('http://localhost/req')", globals={"URL": URL}, number=100000
)
)
)


print(
"Make URL with IPv4 Address and path and port: {:.3f} sec".format(
timeit.timeit(
"URL('http://127.0.0.1:1234/req')", globals={"URL": URL}, number=100000
)
)
)


print(
"Make URL with IPv4 Address and path: {:.3f} sec".format(
timeit.timeit(
"URL('http://127.0.0.1/req')", globals={"URL": URL}, number=100000
)
)
)


print(
"Make URL with IPv6 Address and path and port: {:.3f} sec".format(
timeit.timeit(
"URL('http://[::1]:1234/req')", globals={"URL": URL}, number=100000
)
)
)


print(
"Make URL with IPv6 Address and path: {:.3f} sec".format(
timeit.timeit("URL('http://[::1]/req')", globals={"URL": URL}, number=100000)
)
)
Loading
Loading