def encode(n, proto_factory=TBinaryProtocolFactory()): ab = make_addressbook() start = time.time() for i in range(n): serialize(ab, proto_factory) end = time.time() print("encode\t-> {}".format(end - start))
def test_mix_item(): x_item = container.MixItem() x_item.list_map = [{'foo': 'bar'}] x_item.map_list = {'foo': ['hello', 'world']} x_item2 = deserialize(container.MixItem(), serialize(x_item)) assert x_item == x_item2
def test_map_item(): m_item = container.MapItem() m_item.map_string = {'foo': 'bar'} m_item.map_map_string = {'foo': {'hello': 'world'}} m_item2 = deserialize(container.MapItem(), serialize(m_item)) assert m_item == m_item2
def test_list_item(): l_item = container.ListItem() l_item.list_string = ['foo', 'bar'] l_item.list_list_string = [['foo', 'bar']] b = serialize(l_item) l_item2 = deserialize(container.ListItem(), b) assert l_item == l_item2
def test_mix_item(): x_item = container.MixItem() x_item.list_map = [{"foo": "bar"}] x_item.map_list = {"foo": ["hello", "world"]} b = serialize(x_item) x_item2 = deserialize(container.MixItem(), b) assert x_item == x_item2
def test_map_item(): m_item = container.MapItem() m_item.map_string = {"foo": "bar"} m_item.map_map_string = {"foo": {"hello": "world"}} b = serialize(m_item) m_item2 = deserialize(container.MapItem(), b) assert m_item == m_item2
def test_list_item(): l_item = container.ListItem() l_item.list_string = ["foo", "bar"] l_item.list_list_string = [["foo", "bar"]] b = serialize(l_item) l_item2 = deserialize(container.ListItem(), b) assert l_item == l_item2
def test_list_struct(): l_item = container.ListItem() l_item.list_string = ['foo', 'bar'] * 100 l_item.list_list_string = [['foo', 'bar']] * 100 l_struct = container.ListStruct() l_struct.list_items = [l_item] * 100 b = serialize(l_struct) l_struct2 = deserialize(container.ListStruct(), b) assert l_struct == l_struct2
def decode(n, proto_factory=TBinaryProtocolFactory()): ab = make_addressbook() encoded = serialize(ab) for i in range(n): deserialize(ab, encoded, proto_factory)
def encode(n, proto_factory=TBinaryProtocolFactory()): for i in range(n): ab = make_addressbook() serialize(ab, proto_factory)
phone1.type = addressbook.PhoneType.MOBILE phone1.number = b'555-1212' phone2 = addressbook.PhoneNumber() phone2.type = addressbook.PhoneType.HOME phone2.number = b'555-1234' person = addressbook.Person() person.name = b"Alice" person.phones = [phone1, phone2] person.created_at = 1400000000 ab = addressbook.AddressBook() ab.people = {person.name: person} return ab ab_encoded = serialize(make_addressbook()) def encode(n, proto_factory=TBinaryProtocolFactory()): ab = make_addressbook() start = time.time() for i in range(n): serialize(ab, proto_factory) end = time.time() print("encode\t-> {}".format(end - start)) def decode(n, proto_factory=TBinaryProtocolFactory()): ab = addressbook.AddressBook() start = time.time() for i in range(n):
def make_addressbook(): phone1 = addressbook.PhoneNumber() phone1.type = addressbook.PhoneType.MOBILE phone1.number = b'555-1212' phone2 = addressbook.PhoneNumber() phone2.type = addressbook.PhoneType.HOME phone2.number = b'555-1234' person = addressbook.Person() person.name = b"Alice" person.phones = [phone1, phone2] person.created_at = 1400000000 ab = addressbook.AddressBook() ab.people = {person.name: person} return ab ab_encoded = serialize(make_addressbook()) def encode(n, proto_factory=TBinaryProtocolFactory()): ab = make_addressbook() start = time.time() for i in range(n): serialize(ab, proto_factory) end = time.time() print("encode\t-> {}".format(end - start)) def decode(n, proto_factory=TBinaryProtocolFactory()): ab = addressbook.AddressBook() start = time.time() for i in range(n):