Website performance testing from the command line

There are various commands you can use in the terminal to quickly identify a website’s TTFB, page size, and other load times. Some require the installation of various command line libraries or package managers.

Curl TTFB

curl -s -w 'Testing Website Response Time for :%https://google.com\n\nLookup Time:\t\t%{time_namelookup}\nConnect Time:\t\t%{time_connect}\nAppCon Time:\t\t%{time_appconnect}\nRedirect Time:\t\t%{time_redirect}\nPre-transfer Time:\t%{time_pretransfer}\nStart Time (TTFB):\t%{time_starttransfer}\n\nTotal Time:\t\t%{time_total}\n' -o /dev/null https://google.com


Curl trace-time

curl https://www.google.com --trace-time -v -o /dev/null


Get site cookies

Install PhantomJS: brew cask install phantomjs
Download fetch_data.js here ยป

phantomjs --ignore-ssl-errors=yes --disk-cache=yes /path/to/fetch_data.js https://google.com


Page Speed Insights from the command line

https://github.com/addyosmani/psi
Install with npm: npm install –global psi

psi google.com

You can also filter the results for either desktop or mobile views:

psi --strategy=desktop https://google.com
psi --strategy=mobile https://google.com

GTMetrix reports from the command line

Run the test:

curl --user <gtm-account-email>:<gtm-api-key> --form url=https://google.com --form x-metrix-adblock=0 https://gtmetrix.com/api/0.1/test

Get the results of the test:

curl --user <gtm-account-email>:<gtm-api-key> https://gtmetrix.com/api/0.1/test/{testID} | python -m json.tool


ApacheBench

Install with homebrew: brew install homebrew/apache/ab
Note that the trailing slash at the end of the domain is important. You will get an error if it’s not there.

ab -n 100 https://google.com/


NGHTTP

https://formulae.brew.sh/formula/nghttp2

nghttp -nys https://google.com/


Docker SiteSpeed.io

sitespeed.io https://www.google.com/