Is Rust faster than C?

80 points by steveklabnik


ajdecon

Good post, agreed that there’s no inherent reason for either language to be faster. It’s all project specific.

To add another “social factor” – to the extent that C codebases may be faster as they stand today, it’s often just because they’re much older codebases and have been optimized over a long time. And C has the advantage there just by virtue of being around a long time. Language matters, but so does however many millions of engineer-hours have gone into a project!

mplant

I understand that this is not the point of the article, but one thing that is not mentioned that really excites me about using stronger type systems for low-level programming is that stronger type systems can enable stronger optimizations. The canonical example of this is how Rust added so many noalias attributes that the resulting LLVM IR actually crashed LLVM (this has been fixed for years, but you see my point). Another example is that specialization, which isn’t available yet but may yet be could let you selectively optimize the implementations of certain data types like those that can fit into a SIMD type. There are so many possibilities for strong type systems to improve performance without sacrificing the APIs that we provide people, and that is what really excites me about Rust!

kornel

It’s hard to separate the subtle difference between what’s theoretically possible, and what people do in practice.

For example, C doesn’t have easily accessible hashmaps, so implementations tend to default to linear searches, until it becomes a problem:

https://about.gitlab.com/blog/2025/06/05/how-we-decreased-gitlab-repo-backup-times-from-48-hours-to-41-minutes/

I don’t see such problems in Rust. The hashmaps are easily available, and often less work than writing a substitute.

Another case is multi-threading. Rust programs can sprinkle parallel iterators here and there, and advertise being ✨blazingly fast✨. In C, there needs to be a good reason to deal with multi-threading. Many C libraries don’t even clearly document their multi-threading compatibility.

travis-bradbury

Bryan Cantrill has talked about Rust performance with a perspective that was new and interesting to me. The example was faster in Rust because it turns out to be much easier to use a faster algorithm in this case. https://youtu.be/HgtRAbE1nBM?si=Qk-exSPtzuPzDlZK&t=2450