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

> 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?



Uhm, 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.


> 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-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).


"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.


> 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.


It 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.


> 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/...

> 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.


You 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.


Are 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.


I will explain a third time.

If you compile any C program with a C++ compiler (possibly making trivial changes to account for gratuitous language divergence) you will find, for reasons you note yourself, that it runs at exactly the same speed. NOT, let me emphasize here because this seems to be difficult to process, ever slower than C. Therefore, (try to follow this) C is never faster than C++.

So, it is at best foolish to insist that C can ever be faster than C. The falsehood is trivially exposed.

If you think that C++ is about OO gook and virtual functions, an education awaits. But not here.


> So, it is at best foolish to insist that C can ever be faster than C. The falsehood is trivially exposed.

Enough with the faulty logic, where are the benchmarks proving it? I've still provided more evidence of your assertion than you have.


You don't need a benchmark. Given any C code, you can make a C++ code that runs as fast (just use the same code). This proves that C++ is at least as fast as C.

From there, maybe you could use C++ features to improve the speed (and then C++ is faster) or you could not (and then they have the same speed).


Just take the C code and replace function pointers with templated code. There, the C++ version is now faster.




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

Search: