From 2a39731eb8d5c214ffd750c254b5af397deec2cf Mon Sep 17 00:00:00 2001 From: RangeOfGlitching Date: Sun, 4 Dec 2022 23:56:08 +0800 Subject: [PATCH] compare size with json and proto --- Stream/uav_proto_msg/protomsg/size_test.py | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Stream/uav_proto_msg/protomsg/size_test.py diff --git a/Stream/uav_proto_msg/protomsg/size_test.py b/Stream/uav_proto_msg/protomsg/size_test.py new file mode 100644 index 0000000..5f76587 --- /dev/null +++ b/Stream/uav_proto_msg/protomsg/size_test.py @@ -0,0 +1,51 @@ +import os +from protoMsg import protoMsgWrapper + +def file(message, path, json=False, serial=False): + path = "size/" + path + if serial: + with open(path+".bin", "wb") as f: + f.write(message) + elif json: + with open(path, "w") as f: + f.write(message) + + +flight_info_message = protoMsgWrapper.flight_information(serialized = True) +fly_format_message = protoMsgWrapper.fly_formation(serialized = True) +imu_info_message = protoMsgWrapper.imu_information(serialized = True) +odom_info_message = protoMsgWrapper.odom_information(serialized = True) +flymode_info_message = protoMsgWrapper.flymode_information(serialized = True) +duration_info_message = protoMsgWrapper.duration_information(serialized = True) +timestamp_info_message = protoMsgWrapper.timestamp_information(serialized = True) +serial = [flight_info_message, fly_format_message, imu_info_message, odom_info_message, flymode_info_message, duration_info_message, timestamp_info_message] +serial_name = ["flight_info_message", "fly_format_message", "imu_info_message", "odom_info_message", "flymode_info_message", "duration_info_message", "timestamp_info_message"] +for message in serial: + file(message, serial_name[serial.index(message)], serial=True) + +flight_info_message = protoMsgWrapper.flight_information(tojson = True) +fly_format_message = protoMsgWrapper.fly_formation(tojson = True) +imu_info_message = protoMsgWrapper.imu_information(tojson = True) +odom_info_message = protoMsgWrapper.odom_information(tojson = True) +flymode_info_message = protoMsgWrapper.flymode_information(tojson = True) +duration_info_message = protoMsgWrapper.duration_information(tojson = True) +timestamp_info_message = protoMsgWrapper.timestamp_information(tojson = True) +js = [flight_info_message, fly_format_message, imu_info_message, odom_info_message, flymode_info_message, duration_info_message, timestamp_info_message] +js_name = ["flight_info_message", "fly_format_message", "imu_info_message", "odom_info_message", "flymode_info_message", "duration_info_message", "timestamp_info_message"] +for message in js: + file(message, js_name[js.index(message)], json=True) + + + +serlizl_size = 0 +json_size = 0 +files = sorted(os.listdir("size")) +for file in files: + size = os.path.getsize("size/"+file) + print(file, size) + if file.endswith(".bin"): + serlizl_size += size + else: + json_size += size + +print("json - serial = ", json_size - serlizl_size)