Is Rust faster than C?
Jun 9, 2025
Someone on Reddit recently asked:
What would make a Rust implementation of something faster than a C implementation, all things being the same?
I think this is a great and interesting question! It’s really tough because it ultimately relies on what exactly you mean by “all things being the same.” And I think this is something that makes it hard to compare languages.
Here’s some ways in which you can argue that things are “the same” but also, that they’re not, and what they imply for runtime performance.
Inline Assembly
Rust has inline assembly built into the language. C has inline assembly as a very common compiler extension, to the degree where saying it’s not part of the language is an arguable nitpick.
Here’s an example in Rust:
use std :: arch :: asm; #[ unsafe (no_mangle)] pub fn rdtsc () -> u64 { let lo : u32 ; let hi : u32 ; unsafe { asm! ( "rdtsc" , out ( "eax" ) lo, out ( "edx" ) hi, options (nomem, nostack, preserves_flags), ); } ((hi as u64 ) << 32 ) | (lo as u64 ) }
... continue reading