I'm using the aiohttp HTTP client, and I want to measure latency of my outgoing requests, in order to gauge whether a particular request has different latency under different conditions.
Is it sufficient to do something like the following?
start = time.perf_counter()
async with client.post(url, params=params, data=data) as resp: delta= time.perf_counter() - start
print("Status: {}, Latency: {}".format(resp.status, delta))
I think the above approach could give misleading results depending on other active coroutines when the request is active.
Would it be better to subclass the ClientRequest or ClientResponse classes for this? I've looked through that code a bit and it isn't very clear to me what I would need to change to track request latency.