Open this lesson in your favourite AI. It'll walk you through the why, explain the demo, and quiz you on the try-it list.
Before reaching for an observability platform, curl -w gives you a precise per-phase timing breakdown from anywhere you have shell access — a laptop, a container, a bastion host inside a VPC. It separates DNS from TCP connect from TLS from TTFB from transfer in a single command that takes ten seconds to write. This matters enormously when debugging regional slowness: run the same command from your laptop, from an EC2 instance in us-east-1, and from one in ap-south-1 — the DNS and connect times will differ by hundreds of milliseconds, instantly confirming or ruling out geography as the culprit, without touching the application or waiting for a dashboard to load.
Saving the curl -w format string as a reusable file lets you run a consistent, labelled timing breakdown against any endpoint in seconds. Each field maps directly to a segment in the Chrome DevTools Network waterfall — DNS, connect, TLS, server wait, transfer — so you can correlate what curl shows in the terminal with what the browser reports without guessing which name maps to which phase.
https://api.github.com/zen three times in a row. The first call has DNS time; subsequent calls have near-zero DNS time. Explain why, and how to defeat the cache to always measure real DNS.--http1.1 vs --http2 on the same HTTPS endpoint. Record the TLS handshake time and TTFB for each. Which protocol wins on TTFB and by how much?http://localhost:3000/api/...). Notice that DNS and TLS are 0 ms. Calculate what fraction of a typical external-API round trip is overhead vs actual server work.Use these three in order. Each builds on the one before.
Explain what each curl -w timing field measures and what network or server event it corresponds to.
Walk me through how curl actually measures `time_starttransfer` — what socket event does it attach to, and how does the OS expose that timing to user-space?
I run curl -w against my API from three data-centre locations. Location A shows dns=180ms, Location B shows dns=2ms, Location C shows dns=1ms. What are three things that could cause Location A's DNS to be 90x slower, and how would I confirm each?
# Shell — create the format file once, reuse forever
# curl-format.txt
cat > curl-format.txt << 'EOF'
dns_lookup: %{time_namelookup}s
tcp_connect: %{time_connect}s
tls_handshake: %{time_appconnect}s
ttfb: %{time_starttransfer}s
total: %{time_total}s
http_code: %{http_code}
size_download: %{size_download} bytes
EOF
# Run against any endpoint:
curl -w "@curl-format.txt" -o /dev/null -s https://api.github.com/zen
# Compare two regions (run from different shells / SSH sessions):
# From your laptop:
curl -w "@curl-format.txt" -o /dev/null -s https://YOUR_API/health
# From a cloud VM in ap-south-1:
# ssh cloud-vm "curl -w @curl-format.txt -o /dev/null -s https://YOUR_API/health"go run main.go