Python test Site access speed

Source: Internet
Author: User

#-*-coding:utf-8-*-#@Author: Felix Wang#@time: 2018/8/13 22:13#PIP3 Install PycurlImportPycurl fromIoImportBytesiodeftest_website (URL): C=Pycurl. Curl () Buffer= Bytesio ()#Create a Cache objectC.setopt (c.writedata, buffer)#to set the resource data to be written to the cache objectC.setopt (C.url, URL)#Specify the requested URLC.setopt (C.maxredirs, 5)#Specify the maximum number of HTTP redirectsC.perform ()#ExecutionHttp_code= C.getinfo (Pycurl. HTTP_CODE)#the HTTP status code returnedDns_resolve = C.getinfo (pycurl. Namelookup_time)#time consumed by DNS resolutionHttp_conn_time = C.getinfo (pycurl. Connect_time)#time spent establishing a connectionHttp_pre_trans = C.getinfo (pycurl. Pretransfer_time)#the time consumed from establishing the connection to preparing the transferHttp_start_trans = C.getinfo (pycurl. Starttransfer_time)#the time from when the connection was established to the start of the transferHttp_total_time = C.getinfo (pycurl. Total_time)#total time consumed by transfer endHttp_size_download = C.getinfo (pycurl. Size_download)#Download Packet sizeHttp_size_upload = C.getinfo (pycurl. Size_upload)#Upload Packet sizeHttp_header_size = C.getinfo (pycurl. Header_size)#HTTP Header SizeHttp_speed_downlaod = C.getinfo (pycurl. Speed_download)#Average Download speedHttp_speed_upload = C.getinfo (pycurl. Speed_upload)#Average upload speedHttp_redirect_time = C.getinfo (pycurl. Redirect_time)#time spent in redirection    Print('HTTP response Status:%d'%http_code)Print('DNS resolution Time:%.2f MS'% (Dns_resolve * 1000))    Print('established connection time:%.2f Ms'% (Http_conn_time * 1000))    Print('Ready for transfer time:%.2f MS'% (Http_pre_trans * 1000))    Print("Transfer start time:%.2f Ms"% (Http_start_trans * 1000))    Print("Transfer End time:%.2f Ms"% (Http_total_time * 1000))    Print("REDIRECT time:%.2f Ms"% (Http_redirect_time * 1000))    Print("upload packet size:%d bytes/s"%http_size_upload)Print("Download Packet size:%d bytes/s"%http_size_download)Print("HTTP Header size:%d bytes/s"%http_header_size)Print("average upload speed:%d k/s"% (http_speed_upload/1024))    Print("average download speed:%d k/s"% (http_speed_downlaod/1024))if __name__=='__main__': Test_url='www.baidu.com'test_website (Test_url)

Python test Site access speed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.