3 ms·
Someone should fairly offer as a counterpart any article showing the myriad of reasons why C++ generates much faster code than Rust in most cases. There are man
by hellofunk 10y ago
Someone should fairly offer as a counterpart any article showing the myriad of reasons why C++ generates much faster code than Rust in most cases. There are many such articles out there I've seen from time to time.
- AstralStorm 10y agoTypically by not generating code, such as when more advanced templates are used or constexpr, or by using a specialized or partially specialized version. Traits, while cool, ate not potent enough at times.
- hellofunk 10y agoIt's more than that. While I understand that technically it should be possible to write code in either language that creates the same machine code as the other, the common idioms of each language lead to, in most cases, the C++ generated code being faster. I think it is a classic tradeoff in the safety a language provides vs. its overall performance. For example, the Mozilla team has to use unsafe blocks in the Rust codebase to get the same performance as C++ for those areas where it is important. That is not idiomatic Rust. Mozilla resorts to unsafe blocks just to handle basic doubly-linked lists, as well as optimized hashtables, in order to get similar performance to C++ data structures. My point is that when you stick to the philosophy of Rust, you will in general have slower code that when you write normal idiomatic C++.
- kibwen 10y ago> That is not idiomatic Rust I'm not sure where one would get the idea that `unsafe` would be entirely forbidden in idiomatic Rust. "Idiomatic" Rust acknowledges the danger and subtle pitfalls of unsafe code, and thereby discourages the use of `unsafe`, but also acknowledges that it is still possible to build safe abstractions out of internally-unsafe code. > in order to get similar performance to C++ data structures By Rust's definition, every line of code in a C++ codebase counts as unsafe code. :P If Rust can get equivalent performance to C++ while only using exposing 1% of the code to unsafety, that's an enormous win.
- steveklabnik 10y ago> My point is that when you stick to the philosophy of Rust, you will in general have slower code that when you write normal idiomatic C++. This is just not true. Unsafe != performance. sometimes it does, but not always. For example, the Benchmarks Game programs that are currently fastest have very little unsafe, one of them is entirely for FFI to GMP. Several 100% safe programs have replaced slower programs that used unsafe.