-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathperformances.py
72 lines (51 loc) · 1.59 KB
/
performances.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
62
63
64
65
66
67
68
69
70
71
72
import os
import sys
import time
from create_message import *
HERE = os.path.dirname(os.path.abspath(__file__))
BUILD = os.path.join(HERE, 'build')
lib_path = os.path.join(BUILD, [name for name in os.listdir(BUILD)
if name.startswith('lib')].pop())
if lib_path not in sys.path:
sys.path.insert(0, lib_path)
GOOGLE = True
try:
import messages.test_message_pb2 as google_test
except ImportError:
GOOGLE = False
import test_message_proto as an_test
def main():
if GOOGLE:
t1 = create_google_test()
t2 = create_an_test()
buf = ""
if GOOGLE:
start = time.time()
for i in range(100000):
buf = t1.SerializeToString()
end = time.time()
print("Google took %f seconds to serialize" % (end - start))
start = time.time()
for i in range(100000):
buf = t2.SerializeToString()
end = time.time()
print("Pyrobuf took %f seconds to serialize" % (end - start))
if GOOGLE:
start = time.time()
for i in range(100000):
t1.ParseFromString(buf)
end = time.time()
print("Google took %f seconds to deserialize" % (end - start))
start = time.time()
for i in range(100000):
t2.ParseFromString(buf)
end = time.time()
print("Pyrobuf took %f seconds to deserialize" % (end - start))
start = time.time()
for i in range(100000):
assert t2.HasField('field')
assert t2.HasField('string_field')
end = time.time()
print("HasField took %f seconds" % (end - start))
if __name__ == "__main__":
main()