5 ms·
I've been something wondering something for a while now. Rust is supposed to be a kind of C/C++ replacement, right? But the last I heard it's still much slower.
by imh 11y ago
I've been something wondering something for a while now. Rust is supposed to be a kind of C/C++ replacement, right? But the last I heard it's still much slower. So what's the roadmap to speeding it up? Googling for it failed me.
- dbaupp 11y agoThere may be cases where the compiler doesn't optimise as well as older C/C++ compilers (e.g. in my SIMD work, C/C++ code compiled with GCC occasionally comprehensively beats both the same code compiled with Clang and equivalent Rust with rustc (both built on LLVM) due to better optimisations and instruction selection: not a language issue), or where the pure-Rust libraries aren't as optimised as C/C++ equivalents. However, my experience is that it is rarely a lot slower.
- pcwalton 11y ago> But the last I heard it's still much slower. Not in my experience.
- mbrubeck 11y agoIn general it's possible to write Rust code that is competitive in speed with C and C++. Some safety features like bounds checking do have a small performance cost, though in typical performance-sensitive code it is on the order of 1–2%. You can write unsafe code to avoid the penalty when really necessary. The programs submitted to the benchmark game currently show Rust faster than g++ in some benchmarks, slower in others, but generally in the same ballpark. Of course this changes as the compilers and the programs improve, and the benchmark game isn't representative of anything in particular, but it illustrates some of what's possible. http://benchmarksgame.alioth.debian.org/u64q/compare.php?lang=rust&lang2=gpp http://benchmarksgame.alioth.debian.org/u64q/compare.php?lan...
- Veedrac 11y agoRust has also yet to finalize SIMD, which will help a ton on some where Rust is behind. http://huonw.github.io/blog/2015/08/simd-in-rust/ http://huonw.github.io/blog/2015/08/simd-in-rust/
- eoi 11y ago"How does Rust's speed compare to C/C++" is something of an interesting question. I looked at some micro benchmarks that Rust did poorly on, and listened to some chatter, and this is some of what I saw: 1. Alioth's Regex DNA: this was one of Rust's worst in the benchmark game. The author (burntsushi) of the Regex library being used (written in Rust) hypothesized that it was because of the algorithm the lib used. He worked on it, and now Rust performs excellently on that benchmark. 2. Alioth's n-body: the fast implementations are directly using SIMD. In Rust that is currently on an active path towards stabilization. 3. A networking micro benchmark -- I lost the link here, but the Rust implementation made the simple mistake of allocation a large array by pushing one element at a time to an initially empty dynamic array. Rust compared well after the fix. 4. Rust's buffered reader zeros it's internal buffer, and its default buffer size is [was?] pretty large. This made some IO operations pretty slow without manually tuning the buffer size, and still left some amount of overhead after tuning. In the Reddit thread where this complaint was brought up someone announced a pull (since merged) to significantly reduce the zeroing overhead. I found these examples encouraging, except for the last. The former are regular growing pains of any language ecosystem and benchmark implementation. Only the last looked like an issue where Rust's design might cause a measurable run time cost. In all cases it was cool seeing people tackle the issues and get a good speedup. Worth mentioning is that although Rust's benchmark game results are still behind C's, they are now in a similar ballpark with C++'s. [1] http://benchmarksgame.alioth.debian.org/u64q/performance.php?test=regexdna http://benchmarksgame.alioth.debian.org/u64q/performance.php... , https://www.reddit.com/r/rust/comments/3b2i0f/psa_regex_is_now_slower_than_regexnew/ https://www.reddit.com/r/rust/comments/3b2i0f/psa_regex_is_n... [2] https://www.reddit.com/r/rust/comments/3i85lg/simd_in_rust/ https://www.reddit.com/r/rust/comments/3i85lg/simd_in_rust/ , http://benchmarksgame.alioth.debian.org/u64q/performance.php?test=nbody http://benchmarksgame.alioth.debian.org/u64q/performance.php... [4] https://www.reddit.com/r/rust/comments/3cgaui/trying_to_find_why_python_is_twice_as_fast_as/ https://www.reddit.com/r/rust/comments/3cgaui/trying_to_find... [Rust/C++] http://benchmarksgame.alioth.debian.org/u64q/compare.php?lang=rust&lang2=gpp http://benchmarksgame.alioth.debian.org/u64q/compare.php?lan...