]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
edit middleware docs code sample to use perf_counter as a timer
authorDom <domdent@protonmail.com>
Tue, 6 Aug 2024 13:46:39 +0000 (14:46 +0100)
committerDom <domdent@protonmail.com>
Tue, 6 Aug 2024 13:46:39 +0000 (14:46 +0100)
docs_src/middleware/tutorial001.py

index 6bab3410a6548c3f8b25c9f7e7ed18f9e1e35739..e65a7dade1791c58affe2a745f246a2296ae6935 100644 (file)
@@ -7,8 +7,8 @@ app = FastAPI()
 
 @app.middleware("http")
 async def add_process_time_header(request: Request, call_next):
-    start_time = time.time()
+    start_time = time.perf_counter()
     response = await call_next(request)
-    process_time = time.time() - start_time
+    process_time = time.perf_counter() - start_time
     response.headers["X-Process-Time"] = str(process_time)
     return response