Have you enabled optimizations? I.e. compiled with
cargo build --release
orrustc -Copt-level=3
?
Yes: I do cargo buid --release
You first build with
--release
(and thus optimizations), but then usecargo run
which defaults to debug mode and thus first compiles it again and then runstarget/debug/rust-runtime-speed-test
, which will then be much slower than the release build.
But as pointed out, i was (stupidly ) 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
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 ?