-
-
Save adriangb/9615851b30ea107f0d2860f45a56f523 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import timeit | |
import anyio | |
from fastapi import FastAPI, Depends | |
from httpx import AsyncClient | |
app = FastAPI() | |
Dep0 = Depends(lambda: "dep0") | |
Dep1 = Depends(lambda: "dep1") | |
Dep2 = Depends(lambda: "dep2") | |
Dep3 = Depends(lambda: "dep3") | |
Dep4 = Depends(lambda: "dep4") | |
Dep5 = Depends(lambda: "dep5") | |
Dep6 = Depends(lambda: "dep6") | |
Dep7 = Depends(lambda: "dep7") | |
Dep8 = Depends(lambda: "dep8") | |
Dep9 = Depends(lambda: "dep9") | |
@app.get("/") | |
async def read_main(dep0: str = Dep0, | |
dep1: str = Dep1, | |
dep2: str = Dep2, | |
dep3: str = Dep3, | |
dep4: str = Dep4, | |
dep5: str = Dep5, | |
dep6: str = Dep6, | |
dep7: str = Dep7, | |
dep8: str = Dep8, | |
dep9: str = Dep9): | |
return {"msg": "Hello World"} | |
client = AsyncClient(app=app, base_url="http://example.com") | |
async def test_read_main(): | |
start = timeit.default_timer() | |
for _ in range(3000): | |
response = await client.get("/") | |
assert response.status_code == 200 | |
assert response.json() == {"msg": "Hello World"} | |
elapsed = timeit.default_timer()-start | |
print(f"{elapsed:.2f}") | |
if __name__ == '__main__': | |
anyio.run(test_read_main) | |
# pip install fastapi==0.68.2: 6.18 | |
# pip install fastapi==0.69.0: 8.19 | |
# pip install fastapi==0.70.0: 8.29 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import timeit | |
import anyio | |
from httpx import AsyncClient | |
from xpresso import App, Dependant, Path | |
from xpresso.typing import Annotated | |
Dep0 = Annotated[str, Dependant(lambda: "dep0")] | |
Dep1 = Annotated[str, Dependant(lambda: "dep1")] | |
Dep2 = Annotated[str, Dependant(lambda: "dep2")] | |
Dep3 = Annotated[str, Dependant(lambda: "dep3")] | |
Dep4 = Annotated[str, Dependant(lambda: "dep4")] | |
Dep5 = Annotated[str, Dependant(lambda: "dep5")] | |
Dep6 = Annotated[str, Dependant(lambda: "dep6")] | |
Dep7 = Annotated[str, Dependant(lambda: "dep7")] | |
Dep8 = Annotated[str, Dependant(lambda: "dep8")] | |
Dep9 = Annotated[str, Dependant(lambda: "dep9")] | |
async def read_main(dep0: Dep0, | |
dep1: Dep1, | |
dep2: Dep2, | |
dep3: Dep3, | |
dep4: Dep4, | |
dep5: Dep5, | |
dep6: Dep6, | |
dep7: Dep7, | |
dep8: Dep8, | |
dep9: Dep9): | |
return {"msg": "Hello World"} | |
app = App([Path("/", get=read_main)]) | |
client = AsyncClient(app=app, base_url="http://example.com") | |
async def test_read_main(): | |
start = timeit.default_timer() | |
for _ in range(3000): | |
response = await client.get("/") | |
assert response.status_code == 200 | |
assert response.json() == {"msg": "Hello World"} | |
elapsed = timeit.default_timer()-start | |
print(f"{elapsed:.2f}") | |
if __name__ == '__main__': | |
anyio.run(test_read_main) | |
# pip install xpressso==0.5.0: 4.4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment