From c4050529b560d8c93c4fe2062915efa621322d26 Mon Sep 17 00:00:00 2001 From: Ivan Nikolic Date: Fri, 23 Jan 2026 14:35:59 +0800 Subject: [PATCH] feat: add DimosROS benchmark tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add benchmark test cases for DimosROS pubsub, which uses dimos message types with automatic conversion. This complements existing RawROS tests and allows measuring the dimos↔ROS conversion overhead. --- dimos/protocol/pubsub/benchmark/testdata.py | 48 ++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/dimos/protocol/pubsub/benchmark/testdata.py b/dimos/protocol/pubsub/benchmark/testdata.py index beb140227f..80fc2e3307 100644 --- a/dimos/protocol/pubsub/benchmark/testdata.py +++ b/dimos/protocol/pubsub/benchmark/testdata.py @@ -199,7 +199,7 @@ def redis_msggen(size: int) -> tuple[str, Any]: print("Redis not available") -from dimos.protocol.pubsub.rospubsub import ROS_AVAILABLE, RawROS, RawROSTopic +from dimos.protocol.pubsub.rospubsub import ROS_AVAILABLE, DimosROS, RawROS, RawROSTopic, ROSTopic if ROS_AVAILABLE: from rclpy.qos import QoSDurabilityPolicy, QoSHistoryPolicy, QoSProfile, QoSReliabilityPolicy @@ -267,3 +267,49 @@ def ros_msggen(size: int) -> tuple[RawROSTopic, ROSImage]: msg_gen=ros_msggen, ) ) + + @contextmanager + def dimos_ros_best_effort_pubsub_channel() -> Generator[DimosROS, None, None]: + qos = QoSProfile( + reliability=QoSReliabilityPolicy.BEST_EFFORT, + history=QoSHistoryPolicy.KEEP_LAST, + durability=QoSDurabilityPolicy.VOLATILE, + depth=5000, + ) + ros_pubsub = DimosROS(node_name="benchmark_dimos_ros_best_effort", qos=qos) + ros_pubsub.start() + yield ros_pubsub + ros_pubsub.stop() + + @contextmanager + def dimos_ros_reliable_pubsub_channel() -> Generator[DimosROS, None, None]: + qos = QoSProfile( + reliability=QoSReliabilityPolicy.RELIABLE, + history=QoSHistoryPolicy.KEEP_LAST, + durability=QoSDurabilityPolicy.VOLATILE, + depth=5000, + ) + ros_pubsub = DimosROS(node_name="benchmark_dimos_ros_reliable", qos=qos) + ros_pubsub.start() + yield ros_pubsub + ros_pubsub.stop() + + def dimos_ros_msggen(size: int) -> tuple[ROSTopic, Image]: + topic = ROSTopic(topic="/benchmark/dimos_ros", msg_type=Image) + return (topic, make_data_image(size)) + + # commented to save benchmarking time, + # since reliable and best effort are very similar in performance for local pubsub + # testcases.append( + # Case( + # pubsub_context=dimos_ros_best_effort_pubsub_channel, + # msg_gen=dimos_ros_msggen, + # ) + # ) + + testcases.append( + Case( + pubsub_context=dimos_ros_reliable_pubsub_channel, + msg_gen=dimos_ros_msggen, + ) + )