Home >Backend Development >Golang >Rust vs Go vs C: Database and IoT Application Performance Benchmarks
Rust: A Performance and Security Analysis Through Database and IoT Applications
Rust, lauded for its blend of security and speed [1], shows increasing promise as a professional-grade language [3, 8]. However, the 2021 survey [3] highlighted industry adoption as a primary concern (38%), despite a notable rise in workplace usage (42% to 59%). This study directly addresses this concern by comparing Rust's practical implementation against C and Go in two key application domains: databases (Redis) and IoT (ECHONET Lite).
Methodology: We built two applications, mirroring specifications in C and Go, to evaluate Rust's efficiency and performance. The database application leveraged Redis [19], with comparisons made against unofficial Rust [21] and Go [23] implementations. The IoT application involved implementing the ECHONET Lite protocol [9], comparing C [11], Go [13], Rust [12], and Python [14] implementations.
Evaluation 1: Database Application (Redis)
This evaluation used redis-benchmark
to test SET/GET commands on the official C Redis implementation [19], a Rust subset (mini-redis) [21], and a Go sample implementation (go-redis-server) [23]. Benchmarks were run with 50 threads, 10,000 iterations per run. Due to mini-redis's limited functionality, the evaluation focused solely on performance, using the 99th percentile (p99) as the key metric.
Performance Ranking: C > Go > Rust
The results (shown graphically below) clearly indicate C's superior performance, approximately three times faster than Go and Rust. While both Go and Rust implementations were subsets, the disparity highlights areas for potential optimization.
Rust Performance Analysis: Rust's SET and GET commands were 28% and 41% slower than C, respectively, and significantly slower than Go (78% and 88% slower, respectively). This may be attributed to the incomplete optimization of the Tokio library [20], which mini-redis utilizes. Further, reliance on standard library components like HashMap [17] may have impacted performance.
Go Performance Analysis: Go's go-redis performed surprisingly well, exceeding Rust's performance significantly while remaining competitive with C. The simplicity of the go-redis-server implementation, relying solely on the standard library, suggests potential for further optimization.
Evaluation 2: IoT Application (ECHONET Lite)
This evaluation compared the implementation efficiency and performance of ECHONET Lite [9] client-server implementations across C, Go, Rust, and Python. The implementations shared a common design, with some functional variations across languages (see figure below).
Implementation Efficiency (LOC): Python > Rust ≈ Go > C
Lines of Code (LOC) analysis using Tokei [16] revealed Python's efficiency, followed closely by Rust and Go, with C requiring the most code. (Note: Auto-generated code was excluded.)
Rust Implementation Analysis: Rust’s LOC count, comparable to Go, reflects the language's inherent complexity and the challenges developers face with the compiler and its strict semantics [5]. Limitations in handling traits and lifetimes resulted in design compromises.
C Implementation Analysis: C’s high LOC count stems from the inclusion of self-contained libraries and wrappers for portability.
Go Implementation Analysis: Go's efficiency is attributed to its straightforward implementation and rich standard library, allowing for a direct translation of the C design.
Python Implementation Analysis: Python's low LOC reflects the language’s flexibility and conciseness.
Performance Ranking: Go > C > Rust > Python
Performance was measured using the time
command, executing 10,000 iterations of the ECHONET Lite controller-object interaction. Go demonstrated superior performance, significantly outpacing C, Rust, and Python.
Rust Performance Analysis: Rust’s performance lagged behind Go and C, potentially due to limitations of standard library components like HashMap and Mutex, and constraints imposed by UDPSocket.
C Performance Analysis: While C excelled in user time, its system time was notably higher than Go and Rust, suggesting potential areas for optimization.
Go Performance Analysis: Go’s superior performance highlights its efficiency in handling asynchronous UDP communication.
Python Performance Analysis: Python’s performance was significantly lower than other languages.
Conclusion
From a "Better C" perspective, Go emerges as a strong successor, potentially surpassing even Objective-C. Rust, while offering safety and speed, presents challenges in productivity, interoperability, and programming flexibility. Its compiler-intensive nature and limitations in leveraging existing assets hinder its adoption. Go's implementation efficiency and stable performance make it a robust choice for general-purpose applications. Further investigation into the performance bottlenecks identified in Rust, C, and Go is warranted.
[1] - [27]: References as provided in the original text.
The above is the detailed content of Rust vs Go vs C: Database and IoT Application Performance Benchmarks. For more information, please follow other related articles on the PHP Chinese website!