2 ms·
Yes, but you then also went on to say that no language will ever do it. Rust _has_ consistently beaten C on many of these benchmarks in the past, and continues
by steveklabnik 10y ago
Yes, but you then also went on to say that no language will ever do it. Rust _has_ consistently beaten C on many of these benchmarks in the past, and continues to remain very close in the ones that it's not.
I actually don't think microbenchmarks are a good way to think about performance anyway. There's two reasons:
First, Rust's safety guarantees let you get away with more dangerous things. Consider scoped threads, or non-atomic reference counting.[1] You _could_ write this in C, and you'd do so for a microbenchmark, but not for a real codebase, as it's far too dangerous. Or, you might do it, but end up with bugs that you don't detect, that aren't there in the Rust version.
1: http://blog.faraday.io/saved-by-the-compiler-parallelizing-a-loop-with-rust-and-rayon/ http://blog.faraday.io/saved-by-the-compiler-parallelizing-a...
Secondly, microbenchmarks are often "can the best person at language X write something faster than the best person at language Y"? I don't think that's nearly as interesting as "When an average programmer of languages X and Y write a program, which is faster?" Rust's default patterns and style is already extremely fast. It's not a guarantee, mind you, but for real-world usage, it's the average case that matters more.
- bjourne 10y agoNo, I didn't say that no language will ever beat C. I can't predict the future. Rust has not beaten any highly optimized microbenchmarks that I know of. Like it beats C on the mandelbrot benchmark, but is then beaten by Swift, suggesting that the C implementation isn't very good (http://benchmarksgame.alioth.debian.org/u64q/performance.php?test=mandelbrot http://benchmarksgame.alioth.debian.org/u64q/performance.php...). The reason we have micro benchmarks is because it is so hard to reason about the average case. Yes, code written in Rust could on average be faster than C due to its safety features. But so could Python, Java or Haskell so we're back were we started and can't say anything about relative language performance. It's a small niche, yes, but some people absolutely need to squeeze out every gram of performance, and they should continue to prefer C over Rust.
- igouy 10y ago(The C Mandelbrot program is considerably less extreme.)