Skip to content

Instantly share code, notes, and snippets.

@mikaelvesavuori
Last active January 11, 2021 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikaelvesavuori/9ae9524c4ce46c1cdbb6690aed2d2406 to your computer and use it in GitHub Desktop.
Save mikaelvesavuori/9ae9524c4ce46c1cdbb6690aed2d2406 to your computer and use it in GitHub Desktop.
Measuring response times with Bash

Measuring response times with Bash

Just a simple command that does the basics:

curl domain.tld -s -o output -w 'dns: %{time_namelookup} sec\nconnect: %{time_connect} sec\nuntil first byte: %{time_starttransfer} sec\ntotal: %{time_total} sec\n'

Which results in:

dns: 0,002012 sec
connect: 0,014331 sec
until first byte: 0,091226 sec
total: 0,113247 sec

And on Mac, to repeat add repeat {count}:

repeat 5 curl domain.tld -s -o output -w 'dns: %{time_namelookup} sec\nconnect: %{time_connect} sec\nuntil first byte: %{time_starttransfer} sec\ntotal: %{time_total} sec\n'

You could also add something like the below to your .bashrc or .zshrc (or whatever shell you use), for a simple helper function:

function perf {
  curl -o /dev/null -s -w "Bytes: size_download: %{size_download} bytes\n%{time_connect} + %{time_starttransfer} = %{time_total}\n" "$1"
}

And then run something like perf google.com.

Reading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment