Rust vs. C vs. Go runtime speed comparison

Have you enabled optimizations? I.e. compiled with cargo build --release or rustc -Copt-level=3 ?

Yes: I do cargo buid --release

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.

But as pointed out, i was (stupidly :stuck_out_tongue_closed_eyes: ) running the debug version.
If I do cargo run --release then the runtime goes down from 16.7s to 5.6s. Thx a lot for pointing it out :pray:
Repo updated accordingly: GitHub - oscar6echo/rust-c-go-speed

Much better but still "rust --release" is x3.6 times slower than the best C and 2.4x slower than go.

compiler opt_level runtime ratio vs. best
gcc -O3 1.54 1.0
clang -O3 2.27 1.47
clang -O1 2.3 1.49
go 2.34 1.52
gcc -O2 2.9 1.88
gcc -O1 2.95 1.92
clang -O2 4.35 2.82
rust --release 5.61 3.64
gcc 10.1 6.56
clang 11.53 7.49
rust --debug 16.62 10.79

Is there still room for improvement ?

1 Like