如何准确测量Python套接字连接

时间:2016-07-05 20:41:02

标签: python sockets tcp wireshark

我正在尝试准确测量使用套接字模块完成TCP 3次握手所需的时间。

我正在使用time.perf_counter()来提供时间戳:

try:
    t1 = time.perf_counter()
    sock.connect( (address, int(port)) )
    t2 = time.perf_counter()
    sock.close()   
    conn_time = "%8.5fms" % ( (t2-t1)*1000.0 )

提供所需的粒度,但Wireshark捕获显示计算的时间比实际连接时间长得多。

我不确定问题是与时间模块有关,还是代码从sock.connect移动到t2,即套接字模块在什么时候确定连接成功。

任何有关更准确地衡量连接时间的建议都会受到赞赏。

0 个答案:

没有答案