Performance Comparison of C and Rust Using Common Sorting Algorithms
This article benchmarks C and Rust by implementing five classic sorting algorithms—Bubble, Insertion, Selection, Shell, and Heap Sort—across three data sizes, analyzes the execution times on a macOS system, and discusses the nuanced performance differences and broader implications for language choice.
“C++ and Java evolve faster than C, but I am sure C will remain for a long time.” Dennis Ritchie, Father of the C language
C vs. Rust Speed Comparison
Method
We compared the two languages by implementing five common sorting algorithms—Bubble Sort, Insertion Sort, Selection Sort, Shell Sort, and Heap Sort—and running them on arrays of 1,000; 10,000; and 100,000 random integers, measuring the time each algorithm took.
The implementations use C’s rand() and Rust’s rand::Rng to fill the arrays, and each test is executed 100 times with the average taken.
Test Environment
macOS Catalina on a 2019 16‑inch MacBook Pro, 2.3 GHz 8‑core Intel i9, 16 GB DDR4 memory, clang 12.0.0 (‑O3), rustc 1.45.2 (‑release).
Performance Results
Overall, the results are close. For most algorithms and data sizes, Rust sometimes outperforms C and sometimes the opposite. With 1,000 elements, Rust is faster except for Insertion Sort; with 10,000 elements, C is faster across all algorithms; with 100,000 elements, performance varies per algorithm.
The bar chart below shows that execution times are nearly identical in all cases.
You can try reproducing the tests on your own system. The project code is available at https://github.com/imrushabh/C_vs_Rust .
Conclusion
Determining which language is faster is difficult because it depends on the specific scenario. However, Rust proves to be a strong competitor to C in speed, often matching or exceeding it, while offering memory safety, concurrency support, and an open‑source ecosystem suitable for systems, game engines, browsers, and VR simulations.
Original English article: https://levelup.gitconnected.com/which-is-faster-rust-or-c-lets-find-out-who-is-the-usain-bolt-87495c774c8
High Availability Architecture
Official account for High Availability Architecture.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.