I have written the same simple numerical program in Rust, C, Go, and was hoping that Rust runtime would be about as fast as C. It turns out that it is

Rust vs. C vs. Go runtime speed comparison

submited by
Style Pass
2024-11-10 11:30:05

I have written the same simple numerical program in Rust, C, Go, and was hoping that Rust runtime would be about as fast as C. It turns out that it is 10x slower than the best C compiled program, and 7x slower than the go version.

It is clear that compiler decisions has a big impact on the runtime, as demonstraded by best compiler (gcc) wide distribution of runtimes.

But Rust is such an outlier in here that I MUST have done something VERY suboptimal. However I have fiddled with several variations - unsafe blocks, get_unchecked array access, vec instead of array - the Rust implementation I show in the repo is the fastest I could produce !

Looking forward to expert advice. As it stands, I am a bit disappointed by Rust runtime speed. But I would love to be proven wrong !!

You first build with --release (and thus optimizations), but then use cargo run which defaults to debug mode and thus first compiles it again and then runs target/debug/rust-runtime-speed-test, which will then be much slower than the release build.

Leave a Comment