Timing API

A HTTPRequest tracks timings of various phases. These phases could be the following(naming and meaning similiar to the one can be found in the Chrome DevTools):

As noted, not all phases are present for all requests, but it's also true that new entries are addded for every redirection.

For example a request timing can look like this when it's a first request (no connection is reused):

[TimingCollector Start: '12:42:56'
['Queued': 00:00:00.0030003]
['DNS Lookup': 00:00:00.0050012]
['TCP Connection': 00:00:00.0040004]
['Proxy Negotiation': 00:00:00.3006451]
['TLS Negotiation': 00:00:00.4023915]
['Queued': 00:00:00.0072776]
['Request Sent': 00:00:00.0139910]
['Waiting (TTFB)': 00:00:00.1346626]
['Headers': 00:00:00.0060009]
['Response Received': 00:00:00.0019991]
['Queued for Dispatch': 00:00:00.0020012]
['Finished in': 00:00:00.8809709]]

The code that produced this log entry:

IEnumerator DoTiming()
{
    var request = new HTTPRequest(new Uri("https://httpbin.org/get"));
    yield return request.Send();

    Debug.Log(request.Timing.ToString());
}

As can be seen the three largest entries are Proxy Negotiation, TLS Negotiation and Waiting (TTFB).

But, when a reques can be sent through an already open connection or using HTTP/2, running the code above can produce an entry like this:

[TimingCollector Start: '12:49:48'
['Queued': 00:00:00]
['Request Sent': 00:00:00.0010005]
['Waiting (TTFB)': 00:00:00.1308247]
['Headers': 00:00:00]
['Response Received': 00:00:00]
['Queued for Dispatch': 00:00:00]
['Finished in': 00:00:00.1318252]]

Most of the time spent for waiting for the server's response.

Warning

Timing uses DateTime.Now to calculate time spent between the phases, accuracy depends on this call. It can be used to get a better view on where the plugin had to wait or spend time and not for benchmarking!