Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I wouldn't claim that Rust is "substantially faster" than C right now. In time, the compiler could be able to do more aggressive optimizations than is generally possible in C. But not yet.

Generally, I think the performance differences between C, C++, and Rust are so minute as to be not really worth worrying about. In practice, small differences in the way you write the code makes way more of a difference than anything in the languages. This is not surprising when you consider that the three languages literally share the same compiler backend in many cases (LLVM), and core operations in each language generally map down to the same IR instructions.



It is not unusual for a C++ or Rust program to be 30% faster than the C program it replaces. The reasons are worth studying.

30% may be no great shakes vs the 1000%+ available switching from Python, but in this post-Moore's-Law world, it is nothing to sneeze at.


I think it’s not unusual for any program to be 30% faster than the program it replaces. So far I haven’t seen any specific examples of the C++ or Rust compiler providing a speedup by leveraging additional information input by the programmer. The main speedup seems to be the ability to easily implement more complicated algorithms, and the ability to speedily replace slow one-off implementations with relatively high-quality standard library ones.


Yes, the practicality of dropping in use of a well-optimized library is one of the ways that C++ code often beats C.

Another is the ability to pass a lambda to library function, and compiled directly into it, where C would need to pass a pointer-to-function to be called indirectly.

Both contribute to the showcase sorting example, which is used frequently because it had proven to be understandable, not because it is unique.


My guess is that these languages (C++, Rust) allow for far more optimizations as it is quite discouraged to reinvent the wheel.

Which is a unfortunately a thing in C


One factor is how simple it is to use an efficient data-structure in Rust vs C due to good polymorphism and easy dependency management. In C, importing and using an efficient data structure can be a chore, and so many implementations use suboptimal but more C-friendly structures instead.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: