Delete timeit_test.py
parent
7481dee5ea
commit
6065eaaa20
@ -1,56 +0,0 @@
|
||||
import proto.flyformatioln_pb2 as flyformatioln_pb2
|
||||
import proto.flight_information_pb2 as flight_information_pb2
|
||||
import google.protobuf.json_format as json_format
|
||||
import timeit
|
||||
import orjson
|
||||
import json
|
||||
a = '{"gps": {"LAT": 34123.125, "LON": 23423.123, "ALT": 12123.123}, "heading": 155.12215}'
|
||||
data ={}
|
||||
|
||||
flight_information_msg = flight_information_pb2.flight_information_message()
|
||||
flight_information_msg.gps.LAT = 34123.1231515
|
||||
flight_information_msg.gps.LON = 23423.1231515
|
||||
flight_information_msg.gps.ALT = 12123.1231515
|
||||
flight_information_msg.heading = 155.12215
|
||||
proto_deserialize_msg = flight_information_msg.SerializeToString()
|
||||
|
||||
|
||||
|
||||
def proto_serialize():
|
||||
flight_information_msg = flight_information_pb2.flight_information_message()
|
||||
flight_information_msg.gps.LAT = 34123.1231515
|
||||
flight_information_msg.gps.LON = 23423.1231515
|
||||
flight_information_msg.gps.ALT = 12123.1231515
|
||||
flight_information_msg.heading = 155.12215
|
||||
proto_deserialize_msg = flight_information_msg.SerializeToString()
|
||||
|
||||
|
||||
def proto_deserialize(proto):
|
||||
proto_msg = flight_information_msg.FromString(proto)
|
||||
# js = json_format.MessageToJson(proto_msg, indent=None, preserving_proto_field_name=True)
|
||||
|
||||
def json_serialize(lib):
|
||||
lat = 34123.1231515
|
||||
lon = 23423.1231515
|
||||
alt = 12123.1231515
|
||||
heading = 155.12215
|
||||
dataGpsUpdate = {"gps": {"lat": lat, "lon": lon, "ALT": alt}, "heading":heading}
|
||||
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}")
|
||||
Loading…
Reference in New Issue