Python Performance test Script

Source: Internet
Author: User
Import Httplibimport urllibimport Timeimport JSON class Transaction (object): Def __init__ (self): self . custom_timers = {} def run (self): conn = Httplib. Httpconnection ("localhost:8080") headers = {"Content-type": "Application/json"} #application/x-www-form-urlencoded, "Aceept": "Text/plain" params = ({"Bindhycardinfo": {"Mobileno": "1881026xxxx", "UserId": "2", "Hycardno": Line, " Bankcardno ":" 622xxxxxxxxxxxxx "," IP ":" 127.0.0.1 "}," header ": {" version ":" 1.0.1 "," from ":" + "," to ":" + "," tid ": Line, "Time": "12312", "token": "sew342weer2342", "ext": "}}", start = Time.time () conn.request ("POST", "/core-ope R/rest/bindhycard ", JSON.  Jsonencoder (). Encode (params), headers) response = Conn.getresponse () Response_time = Time.time () data = Response.read () print Data conn.close () Transfer_time = Time.time () self.custom_timers[' res Ponse received '] = Response_time-start self.custom_timers[' content transferred '] = Transfer_time-start if __name__ = = ' __main__ ': File = open ("E://card.txt") while 1: lines = File.readlines () if not lines:break for line in lines:line = Line.strip (' \ n ') trans = Transaction () Trans.run () for the timer in (' Response received ', ' content transf Erred '): print '%s:%.5f secs '% (timer, Trans.custom_timers[timer]) file.close ()
  • 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.