1
1
Wondering if there is an option for curl to print latency in milliseconds? An option that works on either Linux or Mac OSX would be good.
1
1
Wondering if there is an option for curl to print latency in milliseconds? An option that works on either Linux or Mac OSX would be good.
2
Based on this post on Stack Overflow, you would first create a curl format file, naming it curl-format.txt
for example, and putting the following in it:
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
Afterwards, you would pull a request with this command, invoking your text file you created:
curl -w "@curl-format.txt" -o /dev/null -s "http://wordpress.com/"
The results would be something like so:
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
Referring back to the StackOverflow post, it goes into greater detail about what each section of this accomplishes.
Thanks Simon, tried your sample command and works pretty good. Two quick questions, why I need to specify
-o /dev/null
and why need-s
? I think for host name to sending request to, we can specify directly without option like-s
? – Lin Ma – 2016-06-13T22:00:46.8871@LinMa -s makes it skip the progress meter, and -o /dev/null redirects the output to there, so it will not be saved to file – Simon Sheehan – 2016-06-13T23:44:44.040
Thanks Simon, vote up. I tried if I remove -o /dev/null, it will print the html content of the web page, wondering if I add -o /dev/null, output will be redirected to /dev/null and since /dev/null does not exist, no html web page output will be shown, and only performance metrics results will be shown, correct? – Lin Ma – 2016-06-14T23:36:14.440
1Correct, it will not save the output, is effectively what it does. You could also change /dev/null to a folder of your choice, to save it to. – Simon Sheehan – 2016-06-15T02:59:24.293
Thanks Simon, vote up and another quick question is why you need
-s
option? Help said it is silent mode, and wondering your intention of using-s
here. :) – Lin Ma – 2016-06-16T18:36:01.9631@LinMa if you remove -s, you will see a progress bar, give it a shot if you would like :) Just makes for a cleaner terminal output. – Simon Sheehan – 2016-06-16T20:21:29.547
Thanks Simon, vote up, does it support both -X Get and -X POST for
-w "@curl-format.txt"
option? – Lin Ma – 2016-06-16T23:13:35.497BTW, another question is why we need sign
@
? I tried it is not working if I remove@
, just curious how it works. – Lin Ma – 2016-06-16T23:18:22.8901
@LinMa Unfortunately I'm not that familiar with Curl to be able to explain that part. However if you check out the original answer on StackOverflow and comment there, they may be able to get back to you! http://stackoverflow.com/questions/18215389/how-do-i-measure-request-and-response-times-at-once-using-curl
– Simon Sheehan – 2016-06-16T23:20:35.857Thanks Simon, I will mark your reply as answer and start a new question. – Lin Ma – 2016-06-16T23:31:59.210
This answer doesn't say whether or not curl can print in milliseconds. – Elijah Lynn – 2019-08-14T15:59:59.713