Back to Articles

Using cURL to Test the Performance of a Website

By Daniel Cid (@dcid) Posted in: website-performance, educational-guide

cURL is an amazing tool (available by default on macOS and most Linux distributions) that lets you transfer data over many protocols and is commonly used against URLs (i.e., websites). Think of it as a terminal-based browser that doesn’t parse HTML.

Fetch the HTML for a Site

To retrieve the HTML for noc.org:

curl noc.org

Print Only the Response Headers

You can print just the HTTP response headers using -D (dump headers):

curl -s -D - https://noc.org | head
HTTP/2 200
server: nginx
date: Tue, 04 May 2021 17:09:58 GMT
content-type: text/html; charset=UTF-8
vary: Accept-Encoding
noc-cdn-location: cdn-edge-usa-west-la
noc-cdn-cachestatus: HIT

Measure Timing Details (DNS, Connect, TTFB, Total)

One powerful feature of cURL is its ability to expose timing information about your request. You can extract values like DNS lookup time, TCP connect time, time to first byte (TTFB), and total time using cURL’s write-out (-w) variables:

Parameter Description
%{time_namelookup}Time for DNS lookup
%{time_connect}Time to establish the TCP connection
%{time_starttransfer}Time to first byte (TTFB)
%{time_total}Total time for the transfer

To print these four metrics for an HTTPS request to noc.org:

curl -o /dev/null \
  -w "DNS Lookup: %{time_namelookup} sec\nTime to connect: %{time_connect} sec\nTime to first byte: %{time_starttransfer} sec\nTotal time: %{time_total} sec\n" \
  -s https://noc.org
DNS Lookup: 0.001506 sec
Time to connect: 0.012004 sec
Time to first byte: 0.067635 sec
Total time: 0.089123 sec

In this example, DNS is fast (likely cached), the TCP connect takes ~0.01s, TTFB is ~0.06s, and the full response completes around ~0.09s.

Compare with Another Site

For comparison, you can run the same command against another domain:

curl -o /dev/null \
  -w "DNS Lookup: %{time_namelookup} sec\nTime to connect: %{time_connect} sec\nTime to first byte: %{time_starttransfer} sec\nTotal time: %{time_total} sec\n" \
  -s https://cnn.com
DNS Lookup: 0.001483 sec
Time to connect: 0.010323 sec
Time to first byte: 0.055365 sec
Total time: 0.815822 sec

Here, the total time is ~0.82s—significantly higher than the earlier example, which can indicate heavier pages, slower origin responses, or different cache/network characteristics.

Extra Variables You Might Find Useful

You’re not limited to timing. Other helpful variables include:

  • %{size_download} — total bytes downloaded
  • %{response_code} — HTTP status code
  • %{http_version} — negotiated HTTP version

Example:

curl -o /dev/null \
  -w "HTTP Version: %{http_version}\nPage size: %{size_download}\nResponse code: %{response_code}\nDNS Lookup: %{time_namelookup} sec\nTime to connect: %{time_connect} sec\nTime to first byte: %{time_starttransfer} sec\nTotal time: %{time_total} sec\n" \
  -s https://www.cnn.com
HTTP Version: 2
Page size: 1109810
Response code: 200
DNS Lookup: 0.001340 sec
Time to connect: 0.010408 sec
Time to first byte: 0.081696 sec
Total time: 0.744870 sec

Use these metrics to quickly localize performance problems—DNS, network/connect, origin response, or transfer time—and to baseline improvements when enabling CDN caching or tuning your WAF rules.

Trunc — SIEM & Log Management

Centralize logs, search in real time, and ship alerts that matter. Simple, fast, and affordable.

Get Started