[Paper Review] Is Rust C++-fast? Benchmarking System Languages on Everyday Routines
This paper benchmarks Rust and C++ using common system-level algorithms and data structures—such as sorting routines and dictionary operations—on identical hardware. Results show Rust matches or slightly exceeds C++ in Merge Sort and Hybrid Sort, but C++ consistently outperforms Rust in Insertion Sort and dictionary operations, with performance differences attributed to compiler optimizations and language-specific runtime characteristics.
Rust is a relatively new system programming language that has been experiencing a rapid adoption in the past 10 years. Rust incorporates a memory ownership model enforced at a compile time. Since this model involves zero runtime overhead, programs written in Rust are not only memory-safe but also fast, leading to performance comparable to C and C++. Multiple existing benchmarks comparing the performance of Rust with other languages focus on rarely used superficial algorithms, leading to somewhat inconclusive results. In this work, we conduct a comparative performance benchmark of Rust and C++ using commonly used algorithms and data structures rather than exotic ones. Our evaluation shows that the overall performance of Rust is similar to C++, with only minor disadvantage. We also demonstrate that in some Rust routines are slightly faster than the ones of C++.
Motivation & Objective
- To evaluate the performance of Rust and C++ on commonly used system programming algorithms and data structures, moving beyond synthetic or exotic benchmarks.
- To determine whether Rust achieves C++-level performance in real-world, everyday programming routines.
- To identify performance differences in sorting algorithms (Insertion Sort, Merge Sort, Hybrid Sort) and dictionary operations (hash maps vs. balanced binary trees) between the two languages.
- To analyze how compiler optimizations and language-specific design (e.g., Rust’s ownership model) affect runtime performance.
Proposed method
- Implemented semantically identical versions of Insertion Sort, Merge Sort, and Hybrid Sort in both C++ and Rust using standard library containers (vector<double> and Vec<f64>).
- Conducted 10,000 repeated measurements per input size (25 to 1,000 in steps of 25) to compute mean sorting times, excluding random number generation from timing.
- Measured performance across multiple configurations: optimized and non-optimized builds for both C++ (using -O2) and Rust (using --release flag).
- Benchmarked dictionary operations (insertion and deletion) on hash maps and balanced binary trees in both languages under identical hardware and system load.
- Used a single high-end machine (AMD Ryzen Threadripper 2950x, 72GB RAM, Ubuntu 20.04) to minimize environmental variability.
- Collected and analyzed performance data across 16 hybrid sort configurations (K = 16 to 512) and 8 dictionary operation comparisons, visualizing results with performance graphs.
Experimental results
Research questions
- RQ1At what input size does Merge Sort begin to outperform Insertion Sort in Rust and C++, and how does this depend on optimization level?
- RQ2What is the optimal threshold size K for Hybrid Sort in Rust and C++, and how do these values differ between the two languages?
- RQ3Does Rust outperform C++ in Merge Sort, and if so, by how much, under equivalent optimization?
- RQ4How do hash map and balanced binary tree operations compare in performance for insertion and deletion in both Rust and C++?
- RQ5To what extent does C++ outperform Rust in dictionary operations, and is this due to compiler optimization or language-level design?
Key findings
- Rust outperforms C++ in Merge Sort, with the optimized Rust implementation showing faster execution times than the optimized C++ version across all input sizes.
- C++ outperforms Rust in Insertion Sort, with the performance gap being consistent across input sizes and optimization levels.
- The optimal threshold size K for Hybrid Sort is 128 in C++ and 16 in Rust, indicating significant differences in performance characteristics between the two languages.
- Hybrid Sort outperforms both pure Merge Sort and Insertion Sort in both languages, with the performance gain being significantly larger in C++ than in Rust.
- C++ optimized implementation of Hybrid Sort is faster than the Rust equivalent across all input sizes, confirming C++’s edge in low-level performance tuning.
- C++ implementations of hash map and binary tree operations (insertion and deletion) are consistently faster than their Rust counterparts, with deletions being faster than insertions in C++ but similar in Rust.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.