Hacker News new | ask | show | jobs
by eoi 3947 days 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... , https://www.reddit.com/r/rust/comments/3b2i0f/psa_regex_is_n...

[2] https://www.reddit.com/r/rust/comments/3i85lg/simd_in_rust/ , http://benchmarksgame.alioth.debian.org/u64q/performance.php...

[4] https://www.reddit.com/r/rust/comments/3cgaui/trying_to_find...

[Rust/C++] http://benchmarksgame.alioth.debian.org/u64q/compare.php?lan...