Difficulty: 🟡 Medium
Category: Language Comparison
Tags: python, cpp, performance, benchmarking
Execution Type: ros2_publisher
Frequency: low
Python is great for prototyping, logic, and glue code. C++ is used for tight control loops (1kHz+) and image processing. Knowing when to switch languages is a senior robotics engineer skill.
Performance is critical in robotics. Although Python is easier to write, high-frequency tasks often drift or consume high CPU. In this problem, you will implement a high-frequency publisher and measure its actual performance.
- Create a Python node named
high_frequency_publisher - Publish an
Int64message tocounter_topicat exactly 100 Hz (0.01s interval). - Logic: Increment a
self.counterin every callback. - Performance Check: Every 100 messages, calculate and log the average frequency (Hz) or elapsed time.
Output:
- Console Log: A message containing "Hz", "frequency", or "time" every 100 messages.
- Timer drift: Python timers are not real-time; actual frequency may be slightly lower than 100Hz.
- Blocking callbacks: Heavy logic in the callback will drop the frequency significantly.
- High frequency: 100 Hz publishing
- Performance metrics: Timing logged
- Counter accuracy: Correct increment
- Problem #7
- Problem #8
Found an issue with this problem's description, or have a better hint?
Open a PR or report it in Discussions.
Note: TestScripts and reference solutions are maintained by the SimuCode team
and are not part of this open spec. This ensures grading integrity on simucode.online.