diff --git a/Stream/uav_proto_msg/protomsg/ComparePerformance.py b/Stream/uav_proto_msg/protomsg/ComparePerformance.py index e12e6c0..cceecdc 100644 --- a/Stream/uav_proto_msg/protomsg/ComparePerformance.py +++ b/Stream/uav_proto_msg/protomsg/ComparePerformance.py @@ -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 +def readData(fileName:str) -> dict: + with open(fileName, "r") as f: + data_dict = orjson.loads(f.read()) + return data_dict -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 軸標籤 -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 軸標籤 +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() + -fig = plt.figure(2) +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() -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 軸標籤 - - -plt.show() \ No newline at end of file +if __name__ == "__main__": + fileName_size, fileName_time = "Data/sizeData", "Data/timeData" + plotSizeHist(readData(fileName_size)) + plotTimeHist(readData(fileName_time)) \ No newline at end of file diff --git a/Stream/uav_proto_msg/protomsg/Data/sizeData b/Stream/uav_proto_msg/protomsg/Data/sizeData new file mode 100644 index 0000000..c961a57 --- /dev/null +++ b/Stream/uav_proto_msg/protomsg/Data/sizeData @@ -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}} \ No newline at end of file diff --git a/Stream/uav_proto_msg/protomsg/Data/timeData b/Stream/uav_proto_msg/protomsg/Data/timeData new file mode 100644 index 0000000..3960028 --- /dev/null +++ b/Stream/uav_proto_msg/protomsg/Data/timeData @@ -0,0 +1 @@ +{"serialize":{"json":0.710234867001418,"proto":2.2478437370155007},"deserializ":{"json":0.41798062800080515,"proto":0.49253950000274926}} \ No newline at end of file diff --git a/Stream/uav_proto_msg/protomsg/size/duration_info_message b/Stream/uav_proto_msg/protomsg/JsonProtosize/duration_info_message similarity index 100% rename from Stream/uav_proto_msg/protomsg/size/duration_info_message rename to Stream/uav_proto_msg/protomsg/JsonProtosize/duration_info_message diff --git a/Stream/uav_proto_msg/protomsg/size/duration_info_message.bin b/Stream/uav_proto_msg/protomsg/JsonProtosize/duration_info_message.bin similarity index 100% rename from Stream/uav_proto_msg/protomsg/size/duration_info_message.bin rename to Stream/uav_proto_msg/protomsg/JsonProtosize/duration_info_message.bin diff --git a/Stream/uav_proto_msg/protomsg/size/flight_info_message b/Stream/uav_proto_msg/protomsg/JsonProtosize/flight_info_message similarity index 100% rename from Stream/uav_proto_msg/protomsg/size/flight_info_message rename to Stream/uav_proto_msg/protomsg/JsonProtosize/flight_info_message diff --git a/Stream/uav_proto_msg/protomsg/size/flight_info_message.bin b/Stream/uav_proto_msg/protomsg/JsonProtosize/flight_info_message.bin similarity index 100% rename from Stream/uav_proto_msg/protomsg/size/flight_info_message.bin rename to Stream/uav_proto_msg/protomsg/JsonProtosize/flight_info_message.bin diff --git a/Stream/uav_proto_msg/protomsg/size/fly_format_message b/Stream/uav_proto_msg/protomsg/JsonProtosize/fly_format_message similarity index 100% rename from Stream/uav_proto_msg/protomsg/size/fly_format_message rename to Stream/uav_proto_msg/protomsg/JsonProtosize/fly_format_message diff --git a/Stream/uav_proto_msg/protomsg/size/fly_format_message.bin b/Stream/uav_proto_msg/protomsg/JsonProtosize/fly_format_message.bin similarity index 100% rename from Stream/uav_proto_msg/protomsg/size/fly_format_message.bin rename to Stream/uav_proto_msg/protomsg/JsonProtosize/fly_format_message.bin diff --git a/Stream/uav_proto_msg/protomsg/size/flymode_info_message b/Stream/uav_proto_msg/protomsg/JsonProtosize/flymode_info_message similarity index 100% rename from Stream/uav_proto_msg/protomsg/size/flymode_info_message rename to Stream/uav_proto_msg/protomsg/JsonProtosize/flymode_info_message diff --git a/Stream/uav_proto_msg/protomsg/size/flymode_info_message.bin b/Stream/uav_proto_msg/protomsg/JsonProtosize/flymode_info_message.bin similarity index 100% rename from Stream/uav_proto_msg/protomsg/size/flymode_info_message.bin rename to Stream/uav_proto_msg/protomsg/JsonProtosize/flymode_info_message.bin diff --git a/Stream/uav_proto_msg/protomsg/size/imu_info_message b/Stream/uav_proto_msg/protomsg/JsonProtosize/imu_info_message similarity index 100% rename from Stream/uav_proto_msg/protomsg/size/imu_info_message rename to Stream/uav_proto_msg/protomsg/JsonProtosize/imu_info_message diff --git a/Stream/uav_proto_msg/protomsg/size/imu_info_message.bin b/Stream/uav_proto_msg/protomsg/JsonProtosize/imu_info_message.bin similarity index 100% rename from Stream/uav_proto_msg/protomsg/size/imu_info_message.bin rename to Stream/uav_proto_msg/protomsg/JsonProtosize/imu_info_message.bin diff --git a/Stream/uav_proto_msg/protomsg/size/odom_info_message b/Stream/uav_proto_msg/protomsg/JsonProtosize/odom_info_message similarity index 100% rename from Stream/uav_proto_msg/protomsg/size/odom_info_message rename to Stream/uav_proto_msg/protomsg/JsonProtosize/odom_info_message diff --git a/Stream/uav_proto_msg/protomsg/size/odom_info_message.bin b/Stream/uav_proto_msg/protomsg/JsonProtosize/odom_info_message.bin similarity index 100% rename from Stream/uav_proto_msg/protomsg/size/odom_info_message.bin rename to Stream/uav_proto_msg/protomsg/JsonProtosize/odom_info_message.bin diff --git a/Stream/uav_proto_msg/protomsg/JsonProtosize/timestamp_info_message b/Stream/uav_proto_msg/protomsg/JsonProtosize/timestamp_info_message new file mode 100644 index 0000000..53a2984 --- /dev/null +++ b/Stream/uav_proto_msg/protomsg/JsonProtosize/timestamp_info_message @@ -0,0 +1 @@ +"2022-12-08T16:44:17.067479Z" \ No newline at end of file diff --git a/Stream/uav_proto_msg/protomsg/JsonProtosize/timestamp_info_message.bin b/Stream/uav_proto_msg/protomsg/JsonProtosize/timestamp_info_message.bin new file mode 100644 index 0000000..e5a6744 --- /dev/null +++ b/Stream/uav_proto_msg/protomsg/JsonProtosize/timestamp_info_message.bin @@ -0,0 +1 @@ +Ȝ \ No newline at end of file diff --git a/Stream/uav_proto_msg/protomsg/__pycache__/protoMsg.cpython-310.pyc b/Stream/uav_proto_msg/protomsg/__pycache__/protoMsg.cpython-310.pyc index 505eed5..9d7a7be 100644 Binary files a/Stream/uav_proto_msg/protomsg/__pycache__/protoMsg.cpython-310.pyc and b/Stream/uav_proto_msg/protomsg/__pycache__/protoMsg.cpython-310.pyc differ diff --git a/Stream/uav_proto_msg/protomsg/performancePlot/size.png b/Stream/uav_proto_msg/protomsg/performancePlot/size.png new file mode 100644 index 0000000..3e6c7a1 Binary files /dev/null and b/Stream/uav_proto_msg/protomsg/performancePlot/size.png differ diff --git a/Stream/uav_proto_msg/protomsg/performancePlot/time.png b/Stream/uav_proto_msg/protomsg/performancePlot/time.png new file mode 100644 index 0000000..185fd1d Binary files /dev/null and b/Stream/uav_proto_msg/protomsg/performancePlot/time.png differ diff --git a/Stream/uav_proto_msg/protomsg/proto/__pycache__/duration_pb2.cpython-310.pyc b/Stream/uav_proto_msg/protomsg/proto/__pycache__/duration_pb2.cpython-310.pyc index 2d4371c..70a4164 100644 Binary files a/Stream/uav_proto_msg/protomsg/proto/__pycache__/duration_pb2.cpython-310.pyc and b/Stream/uav_proto_msg/protomsg/proto/__pycache__/duration_pb2.cpython-310.pyc differ diff --git a/Stream/uav_proto_msg/protomsg/proto/__pycache__/flight_information_pb2.cpython-310.pyc b/Stream/uav_proto_msg/protomsg/proto/__pycache__/flight_information_pb2.cpython-310.pyc index f1235e9..3b3da9a 100644 Binary files a/Stream/uav_proto_msg/protomsg/proto/__pycache__/flight_information_pb2.cpython-310.pyc and b/Stream/uav_proto_msg/protomsg/proto/__pycache__/flight_information_pb2.cpython-310.pyc differ diff --git a/Stream/uav_proto_msg/protomsg/proto/__pycache__/flyformatioln_pb2.cpython-310.pyc b/Stream/uav_proto_msg/protomsg/proto/__pycache__/flyformatioln_pb2.cpython-310.pyc index 116c999..dfcb462 100644 Binary files a/Stream/uav_proto_msg/protomsg/proto/__pycache__/flyformatioln_pb2.cpython-310.pyc and b/Stream/uav_proto_msg/protomsg/proto/__pycache__/flyformatioln_pb2.cpython-310.pyc differ diff --git a/Stream/uav_proto_msg/protomsg/proto/__pycache__/flymode_pb2.cpython-310.pyc b/Stream/uav_proto_msg/protomsg/proto/__pycache__/flymode_pb2.cpython-310.pyc index 24a1ecc..954d35c 100644 Binary files a/Stream/uav_proto_msg/protomsg/proto/__pycache__/flymode_pb2.cpython-310.pyc and b/Stream/uav_proto_msg/protomsg/proto/__pycache__/flymode_pb2.cpython-310.pyc differ diff --git a/Stream/uav_proto_msg/protomsg/proto/__pycache__/imu_pb2.cpython-310.pyc b/Stream/uav_proto_msg/protomsg/proto/__pycache__/imu_pb2.cpython-310.pyc index b9b0e27..a03d27d 100644 Binary files a/Stream/uav_proto_msg/protomsg/proto/__pycache__/imu_pb2.cpython-310.pyc and b/Stream/uav_proto_msg/protomsg/proto/__pycache__/imu_pb2.cpython-310.pyc differ diff --git a/Stream/uav_proto_msg/protomsg/proto/__pycache__/odom_pb2.cpython-310.pyc b/Stream/uav_proto_msg/protomsg/proto/__pycache__/odom_pb2.cpython-310.pyc index a53ba0a..0f1b1dc 100644 Binary files a/Stream/uav_proto_msg/protomsg/proto/__pycache__/odom_pb2.cpython-310.pyc and b/Stream/uav_proto_msg/protomsg/proto/__pycache__/odom_pb2.cpython-310.pyc differ diff --git a/Stream/uav_proto_msg/protomsg/proto/__pycache__/timestamp_pb2.cpython-310.pyc b/Stream/uav_proto_msg/protomsg/proto/__pycache__/timestamp_pb2.cpython-310.pyc index 0e59f46..ea4569f 100644 Binary files a/Stream/uav_proto_msg/protomsg/proto/__pycache__/timestamp_pb2.cpython-310.pyc and b/Stream/uav_proto_msg/protomsg/proto/__pycache__/timestamp_pb2.cpython-310.pyc differ diff --git a/Stream/uav_proto_msg/protomsg/protoMsg.pyc b/Stream/uav_proto_msg/protomsg/protoMsg.pyc new file mode 100644 index 0000000..a4b8e56 Binary files /dev/null and b/Stream/uav_proto_msg/protomsg/protoMsg.pyc differ diff --git a/Stream/uav_proto_msg/protomsg/size/timestamp_info_message b/Stream/uav_proto_msg/protomsg/size/timestamp_info_message deleted file mode 100644 index 068797d..0000000 --- a/Stream/uav_proto_msg/protomsg/size/timestamp_info_message +++ /dev/null @@ -1 +0,0 @@ -"2022-12-08T07:22:43.602554Z" \ No newline at end of file diff --git a/Stream/uav_proto_msg/protomsg/size/timestamp_info_message.bin b/Stream/uav_proto_msg/protomsg/size/timestamp_info_message.bin deleted file mode 100644 index b85b6da..0000000 --- a/Stream/uav_proto_msg/protomsg/size/timestamp_info_message.bin +++ /dev/null @@ -1 +0,0 @@ -áƜ𜔟 \ No newline at end of file diff --git a/Stream/uav_proto_msg/protomsg/size_test.py b/Stream/uav_proto_msg/protomsg/size_test.py index 19a6813..0c609d6 100644 --- a/Stream/uav_proto_msg/protomsg/size_test.py +++ b/Stream/uav_proto_msg/protomsg/size_test.py @@ -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) + diff --git a/Stream/uav_proto_msg/protomsg/timeit_test.py b/Stream/uav_proto_msg/protomsg/timeit_test.py index 86d2b3d..e1eed8c 100644 --- a/Stream/uav_proto_msg/protomsg/timeit_test.py +++ b/Stream/uav_proto_msg/protomsg/timeit_test.py @@ -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) - - - -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}") \ No newline at end of file +def toFile(fileName:str, compare_time:dict): + with open(fileName, "w+") as f: + f.write(orjson.dumps(compare_time).decode("UTF-8")) + + +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) \ No newline at end of file