]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
📝 Add note about `time.perf_counter()` in middlewares (#12095)
authorSebastián Ramírez <tiangolo@gmail.com>
Sat, 31 Aug 2024 10:15:50 +0000 (12:15 +0200)
committerGitHub <noreply@github.com>
Sat, 31 Aug 2024 10:15:50 +0000 (10:15 +0000)
docs/en/docs/tutorial/middleware.md

index 06fb3f504eca66feb42a278b34d8eb9d4d6d8094..199b593d3eea0ba64116562989b96e627bb9b9b3 100644 (file)
@@ -63,6 +63,12 @@ For example, you could add a custom header `X-Process-Time` containing the time
 {!../../../docs_src/middleware/tutorial001.py!}
 ```
 
+/// tip
+
+Here we use <a href="https://docs.python.org/3/library/time.html#time.perf_counter" class="external-link" target="_blank">`time.perf_counter()`</a> instead of `time.time()` because it can be more precise for these use cases. 🤓
+
+///
+
 ## Other middlewares
 
 You can later read more about other middlewares in the [Advanced User Guide: Advanced Middleware](../advanced/middleware.md){.internal-link target=_blank}.