给定任何网站的URL地址;任务是计算网站的往返时间。
往返时间(RTT)是发送信号所需的总时间或长度,加上接收到该信号的确认所需的时间。此时间还包括信号之间的传播时间。
用户可以通过ping IP地址来确定他/她的往返时间。
往返时间的结果取决于以下原因:
通常,往返时间的持续时间为毫秒,我们以秒为单位显示输出。
Input: www.tutorialspoint.com Output: Time taken:0.3676435947418213 Input: www.indiatoday.in Output: Time taken:0.4621298224721691
我们将使用以下方法来解决给定问题 −
Start Step 1 -> import time Step 2 -> import requests Step 3 -> define a function def roundtriptime(url): Set t1 = time.time() Set req = requests.get(url) Set t2 = time.time() Set t = str(t2-t1) Print Time taken Step 4 -> Initialize url = "http://www.tutorialspoint.com" Step 5 -> Call function roundtriptime(url) Stop
import time import requests # Function to calculate the roundtriptime def roundtriptime(url): # time when the signal is sent t1 = time.time() req = requests.get(url) # time when the acknowledgement # is received t2 = time.time() # total time taken t = str(t2-t1) print("Time taken:" + t) # url address url = "http://www.tutorialspoint.com" roundtriptime(url)
Time taken:0.3676435947418213
以上是计算往返时间(RTT)的C程序的详细内容。更多信息请关注PHP中文网其他相关文章!