Rust vs. C/C++ for Secure Real-Time PLC/RTU Firmware: A Comparative Study of Timing, Memory Predictability, Security, and Deployment
Piyush Shukla · Zenodo (CERN European Organization for Nuclear Research) · 2026
This paper compares C and Rust for secure real-time PLC/RTU firmware using an equivalent simulated control workload. It examines execution timing, memory-allocation behavior, memory-safety protections, and deployment costs. The results showed that both C and heapless Rust completed every measured control workload within the 1 ms period. Under CPU load, their p99 execution times were almost the same: 42.417 µs for C and 41.878 µs for Rust. Static-pool allocation was also nearly identical, averaging 13.510 ns in C and 13.553 ns in Rust. In contrast, Rust’s global-heap allocation was slower and less predictable, with a 33.510 ns mean and a 3292 ns observed maximum. For security, C programs with buffer overflow, use-after-free, double-free, and data-race bugs were detected using sanitizers. Safe Rust rejected use-after-free, double-free, and data-race examples at compile time, while out-of-bounds access was safely handled using a checked lookup. Rust had a larger host executable size—about 472 KB, compared with 34 KB for C. Overall, the paper finds that heapless Rust can provide similar measured performance and better default memory safety for new PLC/RTU components. However, the experiment ran on macOS rather than real PLC hardware or an RTOS, so it does not prove hard-real-time performance or formal WCET guarantees.