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

Any reason to not use httpx.Client and directly use httpx.post? #474

Closed
neochine opened this issue Nov 30, 2024 · 1 comment · Fixed by #475
Closed

Any reason to not use httpx.Client and directly use httpx.post? #474

neochine opened this issue Nov 30, 2024 · 1 comment · Fixed by #475
Labels
help wanted Extra attention is needed

Comments

@neochine
Copy link
Contributor

neochine commented Nov 30, 2024

https://github.com/SuperteamDAO/solathon/blob/master/solathon/core/http.py#L28
A similar library uses httpx.Client which is generally faster than httpx.post. This will also help adding proxy easily: #424 since you need to pass proxy to Client()

import time
import httpx

# Benchmark with httpx.Client()
start = time.time()
with httpx.Client() as client:
    for _ in range(10):
        client.get("https://google.com")
end = time.time()
print(f"With httpx.Client(): {end - start} seconds")

# Benchmark with httpx.get()
start = time.time()
for _ in range(10):
    httpx.get("https://google.com")
end = time.time()
print(f"With httpx.get(): {end - start} seconds")

httpx.Client is generally faster

@michaelhly michaelhly added the help wanted Extra attention is needed label Nov 30, 2024
@michaelhly
Copy link
Owner

Happy to accept a PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants