5 ms·
> Both Rust and C++ can be substantially faster than C, for different reasons. C++ is better at capturing semantics in libraries. Rust knows more about what cod
by flukus 8y ago
> Both Rust and C++ can be substantially faster than C, for different reasons. C++ is better at capturing semantics in libraries. Rust knows more about what code is allowed to do, and can optimize accordingly.
People have been saying this for decades about various languages and C is still the standard for performance except for a few specific cases. How many more decades until we can consider this "sufficiently smart compiler" a myth?
- ncmncm 8y ago"Still the standard" among people who don't know that C++ is faster than C. Fortran used to be the language for what we now call HPC. C was too slow. C++ is used now. This did not happen because Fortran got slower. Instead, C++ got faster. The reasons are interesting. It turns out that to get faster Fortran, your compiler vendor has to code optimizations in the compiler. But in C++ you can code them in a library, and not wait on the attention of a compiler developer.
- flukus 8y ago> C is still the standard among people who don't know that C++ is faster than C. Care to share some examples? I know there are a few specific ones like sorting but every benchmark I've ever seen has c coming out ahead in most tests, especially when c++ features are used. > Fortran used to be the language for what we now call HPC Again that was a fairly specific case usually only seen in scientific applications. From your other post: > 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. Citation needed, this is so far off from every benchmark I've ever seen it's laughable.
- ncmncm 8y agoIt is not possible for a C program to be faster than the C++ version. Compile the C program with a C++ compiler, and they are exactly the same. Then, use C++ features anywhere they make it faster. If you knew C++ I could go into more detail, but if you knew C++ we would not need to have this conversation.
- flukus 8y ago> It is not possible for a C program to be faster than the C++ version. That is simply not true and easily demonstrably false: https://benchmarksgame-team.pages.debian.net/benchmarksgame/faster/c.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/... > Compile the C program with a C++ compiler, and they are exactly the same. Why would I compile a C program with a C++ compiler? But in any case the above link both used gcc and shared most of the compiler backend. > If you knew C++ I could go into more detail, but if you knew C++ we would not need to have this conversation. Your assumptions is wrong on multiple levels, I know C++ (admittedly rusty though) and it is not self evident, the opposite in fact.
- ncmncm 8y agoYou would, if you were scrupulous, compile your C program with a C++ compiler to prove absolutely that C cannot be faster than C++, before going on to make the C++ version faster, using features that do not exist in C. . Your benchmarks demonstrate only that it is possible to write slow code in any language, even a fast one. It would be easy enough to make the C programs equally slow, still proving nothing about either language.
- flukus 8y agoAre you trolling? I Honestly don't know where to start with that post. > You would, if you were scrupulous, compile your C program with a C++ compiler to prove absolutely that C cannot be faster than C++ If my program compiles, which is a big if because c is not a subset of c++, all it would demonstrate is which compiler is better. A c program being compiled with a c++ compiler doesn't gain any type information, it can't make any assumptions that the C compiler couldn't. > before going on to make the C++ version faster, using features that do not exist in C. Which features? It's certainly not going to get faster by throwing in OO abstractions and virtual methods. > Your benchmarks demonstrate only that it is possible to write slow code in any language, even a fast one. Then show me some better ones, so far I've provided more examples supporting your point than you have.
- quicknir 7y agoUhm, citation needed? Most of the most performance critical industries like game dev, high frequency trading, are primarily in C++, not C. Well written C++ tends to be more performant than C largely because there's just much less indirection in using templates than C equivalents (function pointers, void*, etc). And compilers are already smart enough to optimize out most C++ compile time abstractions.
- flukus 7y ago> Uhm, citation needed? Pretty much every benchmark I've ever seen, I provided one further down but here's another one: https://thenewstack.io/which-programming-languages-use-the-least-electricity/ https://thenewstack.io/which-programming-languages-use-the-l... . Yes benchmarks can have many pitfalls but when literally all of them show the same unsurprising result (that more abstraction means worse performance) I think it's safe to trust them. Have you got a citation that shows c++ generally outperforming c? > Most of the most performance critical industries like game dev, high frequency trading, are primarily in C++, not C And I'd be willing to bet that the more critical components look a lot more like c than c++, not "modern c++". > Well written C++ tends to be more performant than C largely because there's just much less indirection in using templates than C equivalents (function pointers, void*, etc) Yes that's one advantage, it's one of the few specific cases where c++ performs better that I outlined. Even then _Generic_ in C can often give you a way to do the same (in an uglier way).