0

As a clumsy approximation, I can measure the process of resolving a DNS name with:

 time getent hosts server.com

and beautifully see how a uncached query can take about 50ms and cached queries about 5ms in average (a pretty cool difference).

But, how can I do the same to measure a simple socket connection? I'm looking for a command like:

time cmd_to_resolve_dns_and_connect_but_no_wait_for_input_or_output

or just

time cmd_to_download --option-to-ignore-everything-after-socket-connect

or just:

cmd_to_download --the-suitable-process-halt-command --option-to-print-time

Any possibility to know the time of connecting to a (HTTP) server is fine for me (I can of course substract to the time the inner DNS name resolution that the command performs; I know that the option parsing and printing consumes time, etc; I don't need an exact measurement, but the command I need it's not for a script, it's for my eyes).

2
  • I mean, you could pretty trivially write a program to do that. Or I guess you could just use time nmap. There might be a set of nc args that allow you to connect and then immediately terminate the connection, but nothing lookin' obvious to me from that manpage. Commented Oct 17, 2017 at 15:38
  • Maybe time tcping -n 1 remoteip remoteport Commented Oct 17, 2017 at 17:45

1 Answer 1

0

Try this :

time nc -zw60 google.com 80

(nc comes from the netcat package)

Or better readable (output):

TIMEFORMAT='%E'
time nc -zw60 google.com 80
2
  • Maybe that is what I'm looking for but I'm not sure though, because it says that -z "scan for listening daemons"; that doesn't mean that the connection is actually performed, but I don't know either if the time of connecting to a socket after it has been identified is negligible or isn't.
    – ABu
    Commented Oct 17, 2017 at 16:18
  • That command should do something else. I have finally ended by writting a little "C++ script" which resolves and connects to an endpoint with boost::asio, and the DNS resolution takes about 4ms (cached), and the connect command about 15ms (~20ms). However, your command gives me 80ms, which is four times longer.
    – ABu
    Commented Oct 17, 2017 at 17:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .