指令測試
curl -o /dev/null -s -w "%{time_namelookup},%{time_connect},%{time_starttransfer},%{time_total}" http://www.google.com
Script
$ vim curl-speed.sh
#!/bin/bash
URL=$1
curl -o /dev/null -s -w \
"DNS Resolve: %{time_namelookup}\n\
Client -> Server: %{time_connect}\n\
Server Respon: %{time_starttransfer}\n\
Total time: %{time_total}\n" \
"${URL}"
$ chmod u+x curl-speed.sh
$ ./curl-speed.sh www.google.com
DNS Resolve: 0.023
Client -> Server: 0.033
Server Respon: 0.041
Total time: 0.041
time_namelookup = DNS 解析時間
time_connect = 建立伺服器 TCP 所花的時間
time_starttransfer = 伺服器 return 的第一個字節
time_total = 整個請求的花費時間