Python 程式計算往返時間 (RTT)


這裡我們將討論如何使用 Python 來獲取往返時間 (RTT)。RTT 是指訊號完成整個行程所需的時間。這意味著從傳送訊號的開始時間到接收到確認訊號的時間這段時間。

RTT 結果因以下不同引數而異。

  • 傳送方的資料傳輸速率。
  • 傳輸介質的性質。
  • 傳送方和接收方之間的實際距離。
  • 傳送方和接收方之間的結點數。
  • 區域網上的流量。
  • 中間點處理的請求數。

示例程式碼

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])

輸出

$ python3 319.RoundTripTime.py https://tutorialspoint.tw/
The Round Trip Time for https://tutorialspoint.tw/ is 0.8301455974578857

$ python3 319.RoundTripTime.py https://www.google.com
The Round Trip Time for https://www.google.com is 0.5217089653015137
$

更新日期:2020-06-26

2K+ 檢視

啟動你的職業生涯

完成課程獲得認證

開始學習
廣告
© . All rights reserved.