您好,欢迎访问一九零五行业门户网

python性能测试脚本

import httplib import urllib import time import 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:1000,to:2000,tid:line,time:12312,token:sew342weer2342,ext:}}) start = time.time() conn.request(post, /core-oper/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['response 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 timer in ('response received', 'content transferred'): print '%s: %.5f secs' % (timer, trans.custom_timers[timer]) file.close()
其它类似信息

推荐信息