Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 3 of 3 for perf_counter (0.23 sec)

  1. docs_src/middleware/tutorial001.py

    from fastapi import FastAPI, Request
    
    app = FastAPI()
    
    
    @app.middleware("http")
    async def add_process_time_header(request: Request, call_next):
        start_time = time.perf_counter()
        response = await call_next(request)
        process_time = time.perf_counter() - start_time
        response.headers["X-Process-Time"] = str(process_time)
    Registered: Sun Oct 27 07:19:11 UTC 2024
    - Last Modified: Tue Aug 06 13:46:39 UTC 2024
    - 365 bytes
    - Viewed (0)
  2. docs/en/docs/tutorial/middleware.md

    ```Python hl_lines="10  12-13"
    {!../../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
    
    Registered: Sun Oct 27 07:19:11 UTC 2024
    - Last Modified: Sun Oct 06 20:36:54 UTC 2024
    - 3.2K bytes
    - Viewed (0)
  3. docs/en/docs/release-notes.md

    * 📝 Add note about `time.perf_counter()` in middlewares. PR [#12095](https://github.com/fastapi/fastapi/pull/12095) by [@tiangolo](https://github.com/tiangolo).
    * 📝 Tweak middleware code sample `time.time()` to `time.perf_counter()`. PR [#11957](https://github.com/fastapi/fastapi/pull/11957) by [@domdent](https://github.com/domdent).
    Registered: Sun Oct 27 07:19:11 UTC 2024
    - Last Modified: Sat Oct 26 16:51:17 UTC 2024
    - 449.4K bytes
    - Viewed (0)
Back to top