Here we will see how Python can be used to get the Round Trip Time (RTT). The RTT is the time which is taken by the entire trip of a signal. It means the time between the starting time when a signal is sent and the receiving time of the acknowledge signal.
The RTT results varies on different parameters like.
- The data transfer rate of the sender’s side.
- The nature of the transmission media.
- The actual distance between the sender and receiver.
- The number of nodes between sender and receiver.
- The amount of traffic on LAN.
- Number of requests handled by intermediate points.
Example Code
import time import requests import sys deffind_roundtriptime(url): initial_time = time.time() #Store the time when request is sent request = requests.get(url) ending_time = time.time() #Time when acknowledged the request elapsed_time = str(ending_time - initial_time) print('The Round Trip Time for {} is {}'.format(url, elapsed_time)) find_roundtriptime(sys.argv[1])
Output
$ python3 319.RoundTripTime.py https://www.tutorialspoint.com/ The Round Trip Time for https://www.tutorialspoint.com/ is 0.8301455974578857 $ python3 319.RoundTripTime.py https://www.google.com The Round Trip Time for https://www.google.com is 0.5217089653015137 $