by flukus · 7y ago · 0 comments
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?
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-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).
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.
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.
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.
That is simply not true and easily demonstrably false: 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.