curl 如何测量它花了多少时间?

参考这篇文章:https://stackoverflow.com/questions/18215389/how-do-i-measure-request-and-response-times-at-once-using-curl

得出了以下的解决方案:

# 创建文件 curl-format.txt
    time_namelookup:  %{time_namelookup}\n
       time_connect:  %{time_connect}\n
    time_appconnect:  %{time_appconnect}\n
   time_pretransfer:  %{time_pretransfer}\n
      time_redirect:  %{time_redirect}\n
 time_starttransfer:  %{time_starttransfer}\n
                    ----------\n
         time_total:  %{time_total}\n

然后适用如下命令:

curl -w "@curl-format.txt" -o /dev/null -s "http://www.baidu.com/"

会打印出:

   time_namelookup:  0.001
      time_connect:  0.037
   time_appconnect:  0.000
  time_pretransfer:  0.037
     time_redirect:  0.000
time_starttransfer:  0.092
                   ----------
        time_total:  0.164

对参数的解释如下:

-w "@curl-format.txt" # 告诉cURL使用我们自己的format的文件
-o /dev/null # 输出结果到/dev/null
-s # 设定访问的URL

 

posted @ 2017-05-23 15:08  WenYao.Huang  阅读(4396)  评论(0编辑  收藏  举报