Home > Article > Backend Development > C program to calculate round trip time (RTT)
Given the URL address of any website; the task is to calculate the round trip time to the website.
Round trip time (RTT) is the total time or length required to send a signal, plus the time required to receive an acknowledgment of that signal. This time also includes the propagation time between signals.
The user can determine his/her round trip time by pinging the IP address.
The result of the round trip time depends on the following reasons:
Typically, the round trip time duration is in milliseconds and we display the output in seconds.
Input: www.tutorialspoint.com Output: Time taken:0.3676435947418213 Input: www.indiatoday.in Output: Time taken:0.4621298224721691
We will use the following method 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)
Time taken:0.3676435947418213
The above is the detailed content of C program to calculate round trip time (RTT). For more information, please follow other related articles on the PHP Chinese website!