3 ms·
Rust is approximately as fast as C. So a straighforward reimplementation of CPython in Rust would be approximately as fast as the original. Rust makes it easie
by orthoxerox 8y ago
Rust is approximately as fast as C. So a straighforward reimplementation of CPython in Rust would be approximately as fast as the original.
Rust makes it easier to write programs that don't leak memory and don't have data races, but it doesn't make them run faster.
- Thaxll 8y agoRust is definitely not as fast as C, it's most likely not as fast as C++
- dralley 8y agoIt's within 5-10% on average, sometimes faster, usually a little slower, very rarely slower by much. The person you're responding to said "approximately". I feel like this is needless pedantry. Rust also allows you to make architectural decisions in the name of performance that would be completely unmaintainable in C. See: the Servo project.
- arcticbull 8y agoFurther, it should be possible for Rust to eventually reach a state where it's faster than C because of the lack of pointer aliasing. This opens up a whole host of optimization opportunities, allowing it to get closer in performance to Fortran (which is intrinsically the fastest of the bunch).
- dodobirdlord 8y agoIndeed, it's available but currently disabled due to a bug in LLVM that can cause incorrect code generation. https://github.com/rust-lang/rust/issues/54878 https://github.com/rust-lang/rust/issues/54878 This is not the first time it has been disabled due to an LLVM bug. https://github.com/rust-lang/rust/issues/31681 https://github.com/rust-lang/rust/issues/31681
- dodobirdlord 8y agoWhat makes you say that? Optimized machine code is for the most part optimized machine code, and unsurprisingly benchmarks tend to come down about even. The bunchmarks game currently has them down as C vs. Rust: 6 wins for C, one draw, 3 wins for Rust C++ vs. Rust: 5 wins for C++, two draws, 3 wins for Rust The wins one way or another are also not by particularly large margins. https://benchmarksgame-team.pages.debian.net/benchmarksgame/faster/gcc-rust.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/... https://benchmarksgame-team.pages.debian.net/benchmarksgame/faster/gpp-rust.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/... This may go on to shift marginally in Rust's favor once a soundness bug related to non-aliasing of references is fixed in LLVM and the compiler can safely leverage some guarantees that Rust provides that C and C++ cannot.
- pjmlp 8y agoAny update on that bug being fixed?
- afiori 8y agoHere the optimism would be around removing the GIL and similar stuff, it is not that rust would make the same architecture magically faster but that it could allow a better one. Also others have noted that speed was not a primary focus of CPython