-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
62 lines (51 loc) · 1.75 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import json
import random
import list_item_pb2
import time
import os
from google.protobuf.json_format import Parse
from google.protobuf.internal import api_implementation
class MyClass:
def __init__(self, name, last_name):
self.name = name
self.last_name = last_name
self.age = random.randint(10, 30)
def represent(self):
print(self.name + self.last_name)
def toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__,
sort_keys=True)
@staticmethod
def load(self, dictionary):
self.__dict__ = dictionary
if __name__=='__main__':
TEST_SIZE = int(os.getenv('TEST_SIZE'))
LIST_SIZE = 1
print(api_implementation.Type())
#serializing
print(f'Test size is {TEST_SIZE}')
print('starting to serialize items...')
serialized_lists = []
start_time = time.time()
for _ in range(TEST_SIZE):
tmp = []
for _ in range(LIST_SIZE):
list_item = list_item_pb2.ListItem()
list_item.commodity_id = random.randint(1, 1000)
list_item.has_video = random.choice([True, False])
tmp.append(list_item)
list = list_item_pb2.List()
list.listItem.extend(tmp)
serialized_lists.append(list.SerializeToString())
print('finished creating items.')
print(f'Total time {time.time() - start_time}')
#deserializing
print('starting deserializing items...')
deserialized_lists = []
start_time = time.time()
for serialized_list in serialized_lists:
list = list_item_pb2.List()
list.ParseFromString(serialized_list)
deserialized_lists.append(list)
print('finished deserializing.')
print(f'Total time {time.time() - start_time}')