Given an Url address of any website; the task is to calculate the round trip time of a website.
Round Trip Time(RTT) is the total time or the length of a time which is taken to send a signal plus the time taken to receive the acknowledgement of that signal to be received. This time also consist of the propagation times between two points of a signal.
An end user can determine his/her round trip time from an IP address by pinging that address.
The Round Trip time’ result depends upon the following reasons −
Generally the duration of Round Trip Time will be in milliseconds and we displaying output in Seconds.
Input: www.tutorialspoint.com Output: Time taken:0.3676435947418213 Input: www.indiatoday.in Output: Time taken:0.4621298224721691
Approach we will be using to solve the given problem −
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)