Skip to content

@vincentwyshan /loadtest.py
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#coding=utf8
import time
import simplejson as json
from cadaapi.stock.ttypes import *
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
def load(data):
head = data[0]
data = data[1:]
body = []
head = [str(v) for v in head]
for row in data:
row = row[0]
try:
body.append(RatingByReport(**dict(zip(head,row))))
except:import pdb;pdb.set_trace()
result = TableRatingByReport(head=head, body=body)
return result
def ser(data):
transportOut = TTransport.TMemoryBuffer()
protocolOut = TBinaryProtocol.TBinaryProtocol(transportOut)
data.write(protocolOut)
vals = transportOut.getvalue()
return vals
def test_thrift(data):
print >>open('/tmp/test.thrift', 'w'), ser(data)
now = time.time()
print 'start:', now
for i in range(10):
print '\tFile length:', len(ser(data))
now2 = time.time()
print 'end:', now2
print 'elapse:', now2-now
def test_json(data):
now = time.time()
print 'start:', now
for i in range(10):
print '\tFile length:', len(json.dumps(data))
now2 = time.time()
print 'end:', now2
print 'elapse:', now2-now
if __name__ == '__main__':
rawdata = json.loads(open('/tmp/test.json', 'r').read())
data = load(rawdata)
print 'Test thrift'
test_thrift(data)
print '\n\nTest json'
test_json(rawdata)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.