Using CURL to measure latency
-
In curl, the total time the command takes to execute (including DNS resolution, TCP connection time, data transfer time, etc.) can be retrieved using some built-in variables.
To use these variables, you can use the -w or --write-out option in the curl command.
curl -o /dev/null -s -w 'Lookup time:\t%{time_namelookup}\nConnect time:\t%{time_connect}\nPreXfer time:\t%{time_pretransfer}\nStartXfer time:\t%{time_starttransfer}\n\nTotal time:\t%{time_total}\n' http://example.com
This information will be an approximation of latency, not a direct measurement. Latency in a network context is usually defined as the time it takes for a packet of data to get from one designated point to another. In the context of a curl command, it would usually mean the time taken to establish a TCP connection plus the time taken for the HTTP request and response.