4 ms·
We already do pay attention to performance. In general, Rust should already be in the same league as C or C++. Please open issues if you find something that isn
by steveklabnik 12y ago
We already do pay attention to performance. In general, Rust should already be in the same league as C or C++. Please open issues if you find something that isn't.
- kibwen 12y agoAnd even more important than current benchmark numbers is that the language is explicitly designed to be optimizable, and takes the idea of "zero-cost abstractions" seriously. I can count on two fingers the number of places where we impose dynamic checks by default in the name of safety, and one of those can be unsafely turned off and the other can be safely disabled with proper code structuring. (Theoretically we can also leverage Rust's ownership rules to automatically generate aliasing information. When implemented this should be an across-the-board speed boost for all Rust code in existence, in a way that C and C++ compilers can only dream of.)
- tpush 12y agoWould there also be a performance boost compared to C code which properly uses 'restrict'?
- kibwen 12y agoThe underlying compiler backend would use the same alias optimization pass for both Rust and C. Rust's advantages here are that all Rust code is automatically eligible for such optimization without the programmer having to do any work at all, and whereas a programmer can get `restrict` usage wrong (or alternately fail to have the confidence that a given pointer is truly unaliasable), the Rust compiler has perfect information. To be fair, there are also optimizations that C can do that Rust can't, often resulting from C's undefined behavior.
- tpush 12y agoThanks for the information! Looking very much forward to rust 1.0.
- bjz_ 12y agoRust's type system enforces a great deal more invariants in terms of lifetimes, ownership and mutability than C, which enforces virtually nothing. This should therefore give the compiler far more room make optimizations without the fear of changing the semantics of the program. So in the future safe, idiomatic Rust code should be able approach the performance of highly optimized C code, without having to drop resort to unsafe code (note of course that C is implicitly unsafe).
- hugh4life 12y agoI noticed that in the last round of the language shootout benchmarks that rust was significantly behind C++(and I also noticed that this was being addressed on the rust reddit). I'd like to see more benchmarking done between rust and C++ where there is a solution for each language that is idiomatic or safe while another solution optimizes for performance.
- steveklabnik 12y agoThere's a few reasons for this: 1. We haven't put in the time for the benchmarks game, because we're too busy working on the language. 2. IIRC, the C++ version uses GMP, and we don't, because licensing. You can install a package if you need GMP, but that doesn't work for the benchmarks game. > I'd like to see more benchmarking done between rust and C++ where there is a solution for each language that is idiomatic or safe while another solution optimizes for performance. Much of Rust's safety comes with no runtime overhead, but some of it does.
- igouy 12y ago> but that doesn't work for the benchmarks game. fyi http://benchmarksgame.alioth.debian.org/u64/program.php?test=pidigits&lang=rust&id=2 http://benchmarksgame.alioth.debian.org/u64/program.php?test...
- igouy 12y ago> You can install a package if you need GMP, but that doesn't work for the benchmarks game. Why doesn't that work for the benchmarks game? > Much of Rust's safety comes with no runtime overhead, but some of it does. I guess he'd like to find out how much overhead.