2

I tried to test the speed of my website, so I used

time curl "http://google.com"

The result ended with

real 0m15.589s user 0m0.012s sys 0m0.000s

I tried to see what took so long, so I timed hosts time host google.com

and got

real 0m0.180s user 0m0.008s sys 0m0.004s

And time curl "http://216.58.217.206"

and got

real 0m0.163s user 0m0.000s sys 0m0.004s

0.18 s + 0.16 s is much less than 15.58s!!

Why does curl take so long?

2
  • Hi. This question is probably better suited for Serverfault. Moreover, I would add more detail. There are many, many factors that could have influenced the difference in speed. (Cached response, Cached DNS, etc)
    – Eddie
    Dec 20, 2015 at 4:27
  • Because you're comparing apples to oranges. There's a lot going on with an invocation of curl.
    – Ricky
    Dec 20, 2015 at 6:49

2 Answers 2

0

host google.com only resolves an A record. curl "http://google.com" sends an HTTP GET request. Sending HTTP messages is much more work than resolving host names.

Moreover, both curl "http://google.com" and host google.com trigger the local DNS resolver. After the desired record has been resolved, host has done its work, while curl is just beginning to do its actual work.

In short: curl is a tool for HTTP. host is a tool for DNS. curl implicitly depends on DNS. host explictily is designed for DNS.

0

When you do curl "http://google.com", you are specifying the name; means it has loopup/resolve the name to IP(First connects to DNS server, resolve the IP) and then connects/curl the IP(In your case Google!). It will take some time relatively.

Now, Check the MAN page of host

"host" is a simple utility for performing DNS lookups

It is only connecting to DNS/Resolving the name to IP. That's it!

curl "http://216.58.217.206", In this case, there is no need to reslove/loopup the name. Because, as you know you're directly giving the IP. So, simply connecting to google!

Not the answer you're looking for? Browse other questions tagged or ask your own question.