Curl 输出耗时信息

发布时间 2023-05-29 18:00:13作者: SangriaChant

操作方法

默认情况下,curl 不会输出耗时信息,若需要输出耗时,需要使用 -w, --write-out FORMAT 选项配置 Write Out 格式。

curl -w "\n\ntime_total:  %{time_total}s\n" https://www.example.com

Write Out 中支持的变量请参考:
https://everything.curl.dev/usingcurl/verbose/writeout#available-write-out-variables

也可以使用文件

curl -w "@curl-format.txt" https://www.example.com

一个简单的文件格式参考如下:

\n\n
time_namelookup:  %{time_namelookup}s\n
time_connect:  %{time_connect}s\n
time_appconnect:  %{time_appconnect}s\n
time_pretransfer:  %{time_pretransfer}s\n
time_redirect:  %{time_redirect}s\n
time_starttransfer:  %{time_starttransfer}s\n
----------\n
time_total:  %{time_total}s\n