performance test finish
This commit is contained in:
@@ -1,64 +1,66 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import orjson
|
||||
|
||||
|
||||
fig = plt.figure(1)
|
||||
plt.subplot(421) # 設定子圖 421 表示4*2 位置1 不想塞子圖就註解
|
||||
duration_info_message = 8
|
||||
duration_info_message_bin = 4
|
||||
|
||||
width=0.3
|
||||
x = ['set1']
|
||||
x1=np.arange(len(x)) #X 軸 (第一組)
|
||||
y1=(8) #Y 軸1=duration_info_message
|
||||
x2=[p + width for p in x1] #X 軸 (第二組)
|
||||
y2=(4) #Y 軸2=duration_info_message_bin
|
||||
plt.bar(x1, y1, label='Json', width=0.1) #繪製長條圖
|
||||
plt.bar(x2, y2, label='protobuf', width=0.1) #繪製長條圖
|
||||
plt.xticks([p + width/2 for p in x1], x) #設定 X 軸刻度標籤
|
||||
plt.legend() #顯示圖例
|
||||
plt.title('duration_info') #設定圖形標題
|
||||
# plt.xlabel('x label') #設定 X 軸標籤
|
||||
plt.ylabel('MB') #設定 Y 軸標籤
|
||||
def readData(fileName:str) -> dict:
|
||||
with open(fileName, "r") as f:
|
||||
data_dict = orjson.loads(f.read())
|
||||
return data_dict
|
||||
|
||||
|
||||
|
||||
plt.subplot(422)
|
||||
flight_info_message=85
|
||||
flight_info_message_bin=22
|
||||
width=0.3
|
||||
x = ['set2']
|
||||
x1=np.arange(len(x)) #X 軸 (第一組)
|
||||
y1=(85) #Y 軸1=duration_info_message
|
||||
x2=[p + width for p in x1] #X 軸 (第二組)
|
||||
y2=(22) #Y 軸2=duration_info_message_bin
|
||||
plt.bar(x1, y1, label='Json', width=0.1) #繪製長條圖
|
||||
plt.bar(x2, y2, label='protobuf', width=0.1) #繪製長條圖
|
||||
plt.xticks([p + width/2 for p in x1], x) #設定 X 軸刻度標籤
|
||||
plt.legend() #顯示圖例
|
||||
plt.title('flight_info') #設定圖形標題
|
||||
# plt.xlabel('x label') #設定 X 軸標籤
|
||||
plt.ylabel('MB') #設定 Y 軸標籤
|
||||
|
||||
|
||||
|
||||
fig = plt.figure(2)
|
||||
|
||||
json=404
|
||||
serial=97
|
||||
width=0.3
|
||||
x = ['set']
|
||||
x1=np.arange(len(x)) #X 軸 (第一組)
|
||||
y1=(404) #Y 軸1=duration_info_message
|
||||
x2=[p + width for p in x1] #X 軸 (第二組)
|
||||
y2=(97) #Y 軸2=duration_info_message_bin
|
||||
plt.bar(x1, y1, label='Json', width=0.1) #繪製長條圖
|
||||
plt.bar(x2, y2, label='protobuf', width=0.1) #繪製長條圖
|
||||
plt.xticks([p + width/2 for p in x1], x) #設定 X 軸刻度標籤
|
||||
plt.legend() #顯示圖例
|
||||
plt.title('flight_info') #設定圖形標題
|
||||
# plt.xlabel('x label') #設定 X 軸標籤
|
||||
plt.ylabel('MB') #設定 Y 軸標籤
|
||||
def plotSizeHist(size_data_dict:dict):
|
||||
postion = 421
|
||||
for OutterKey in size_data_dict:
|
||||
plt.subplot(postion)
|
||||
plt.ylim(top=140)
|
||||
postion += 1
|
||||
size = list(size_data_dict[OutterKey].values())
|
||||
width=0.3
|
||||
x = ['']
|
||||
x1=np.arange(len(x))
|
||||
y1=(size[0])
|
||||
x2=[p + width for p in x1]
|
||||
y2=(size[1])
|
||||
plt.bar(x1, y1, label='Json', width=0.1)
|
||||
plt.bar(x2, y2, label='protobuf', width=0.1)
|
||||
plt.xticks([p + width/2 for p in x1], x)
|
||||
plt.legend()
|
||||
plt.title(OutterKey)
|
||||
plt.ylabel('MB')
|
||||
figure = plt.gcf() # get current figure
|
||||
figure.set_size_inches(18, 14)
|
||||
plt.savefig("performancePlot/size.png")
|
||||
plt.show()
|
||||
|
||||
|
||||
|
||||
plt.show()
|
||||
def plotTimeHist(time_data_dict:dict):
|
||||
postion = 211
|
||||
for OutterKey in time_data_dict:
|
||||
plt.subplot(postion)
|
||||
postion += 1
|
||||
size = list(time_data_dict[OutterKey].values())
|
||||
width=0.3
|
||||
x = ['']
|
||||
x1=np.arange(len(x))
|
||||
y1=(size[0])
|
||||
x2=[p + width for p in x1]
|
||||
y2=(size[1])
|
||||
plt.bar(x1, y1, label='Json', width=0.1)
|
||||
plt.bar(x2, y2, label='protobuf', width=0.1)
|
||||
plt.xticks([p + width/2 for p in x1], x)
|
||||
plt.legend()
|
||||
plt.title(OutterKey)
|
||||
plt.ylabel('second')
|
||||
|
||||
plt.savefig("performancePlot/time.png")
|
||||
plt.show()
|
||||
|
||||
if __name__ == "__main__":
|
||||
fileName_size, fileName_time = "Data/sizeData", "Data/timeData"
|
||||
plotSizeHist(readData(fileName_size))
|
||||
plotTimeHist(readData(fileName_time))
|
||||
@@ -0,0 +1 @@
|
||||
{"flight_info_message":{"json":85,"proto":22},"fly_format_message":{"json":55,"proto":7},"imu_info_message":{"json":130,"proto":34},"odom_info_message":{"json":59,"proto":17},"flymode_info_message":{"json":38,"proto":2},"duration_info_message":{"json":8,"proto":4},"timestamp_info_message":{"json":29,"proto":11},"Total":{"json":404,"proto":97}}
|
||||
@@ -0,0 +1 @@
|
||||
{"serialize":{"json":0.710234867001418,"proto":2.2478437370155007},"deserializ":{"json":0.41798062800080515,"proto":0.49253950000274926}}
|
||||
@@ -0,0 +1 @@
|
||||
"2022-12-08T16:44:17.067479Z"
|
||||
@@ -0,0 +1 @@
|
||||
á¨ÈœÀ³÷
|
||||
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 70 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +0,0 @@
|
||||
"2022-12-08T07:22:43.602554Z"
|
||||
@@ -1 +0,0 @@
|
||||
áƜ
|
||||
@@ -1,8 +1,10 @@
|
||||
import os
|
||||
from protoMsg import protoMsgWrapper
|
||||
import copy
|
||||
import orjson
|
||||
|
||||
def file(message, path, json=False, serial=False):
|
||||
path = "size/" + path
|
||||
path = "JsonProtosize/" + path
|
||||
if serial:
|
||||
with open(path+".bin", "wb") as f:
|
||||
f.write(message)
|
||||
@@ -35,20 +37,33 @@ def json_msg():
|
||||
for message in js:
|
||||
file(message, serial_name[js.index(message)], json=True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
def toFile(fileName:str, compare_size:dict):
|
||||
with open(fileName, "w+") as f:
|
||||
f.write(orjson.dumps(compare_size).decode("UTF-8"))
|
||||
|
||||
if __name__=='__main__':
|
||||
serial_name = ["flight_info_message", "fly_format_message", "imu_info_message", "odom_info_message", "flymode_info_message", "duration_info_message", "timestamp_info_message"]
|
||||
proto_msg()
|
||||
json_msg()
|
||||
serlizl_size = 0
|
||||
json_size = 0
|
||||
size = {"flight_info_message":{"Json":None, "Proto":None}}
|
||||
files = sorted(os.listdir("size"))
|
||||
compare_size_prototype = {"json":None, "proto":None}
|
||||
compare_size = dict((name, copy.deepcopy(compare_size_prototype))for name in serial_name)
|
||||
files = sorted(os.listdir("JsonProtosize"))
|
||||
for file in files:
|
||||
size = os.path.getsize("size/"+file)
|
||||
print(file, size)
|
||||
size = os.path.getsize("JsonProtosize/"+file)
|
||||
|
||||
if file.endswith(".bin"):
|
||||
name = file.replace(".bin", "")
|
||||
compare_size[name]["proto"] = size
|
||||
serlizl_size += size
|
||||
else:
|
||||
compare_size[file]["json"] = size
|
||||
json_size += size
|
||||
|
||||
compare_size["Total"] = {"json":json_size, "proto":serlizl_size}
|
||||
print(compare_size)
|
||||
print("json - serial = ", json_size - serlizl_size)
|
||||
fileName = "Data/sizeData"
|
||||
toFile(fileName, compare_size)
|
||||
|
||||
|
||||
@@ -38,19 +38,26 @@ def json_serialize(lib):
|
||||
data.update(dataGpsUpdate)
|
||||
js = lib.dumps(data).decode("utf-8")
|
||||
# print(js)
|
||||
|
||||
def json_deserialize(lib):
|
||||
js = lib.loads(a)
|
||||
# print(js)
|
||||
|
||||
def toFile(fileName:str, compare_time:dict):
|
||||
with open(fileName, "w+") as f:
|
||||
f.write(orjson.dumps(compare_time).decode("UTF-8"))
|
||||
|
||||
|
||||
|
||||
proto_serialize_time = timeit.timeit(lambda: proto_serialize(), number = 150000)
|
||||
proto_deserialize_time = timeit.timeit(lambda: proto_deserialize(proto_deserialize_msg), number = 150000)
|
||||
json_serialize_time = timeit.timeit(lambda: json_serialize(orjson), number = 150000)
|
||||
json_deserialize_time = timeit.timeit(lambda: json_deserialize(orjson), number = 150000)
|
||||
print(f"proto_serialize_time: {proto_serialize_time}")
|
||||
print(f"json_serialize_time: {json_serialize_time}")
|
||||
print()
|
||||
print(f"proto_deserialize_time: {proto_deserialize_time}")
|
||||
print(f"json_deserialize_time: {json_deserialize_time}")
|
||||
if __name__=='__main__':
|
||||
proto_serialize_time = timeit.timeit(lambda: proto_serialize(), number = 1000000)
|
||||
proto_deserialize_time = timeit.timeit(lambda: proto_deserialize(proto_deserialize_msg), number = 1000000)
|
||||
json_serialize_time = timeit.timeit(lambda: json_serialize(orjson), number = 1000000)
|
||||
json_deserialize_time = timeit.timeit(lambda: json_deserialize(orjson), number = 1000000)
|
||||
time_dict = {"serialize": {"json": json_serialize_time, "proto":proto_serialize_time}, "deserializ":{"json": json_deserialize_time, "proto":proto_deserialize_time}}
|
||||
print(f"proto_serialize_time: {proto_serialize_time}")
|
||||
print(f"json_serialize_time: {json_serialize_time}")
|
||||
print()
|
||||
print(f"proto_deserialize_time: {proto_deserialize_time}")
|
||||
print(f"json_deserialize_time: {json_deserialize_time}")
|
||||
fileName = "Data/timeData"
|
||||
toFile(fileName, time_dict)
|
||||
Reference in New Issue
Block a user