3 ms·
> C++ is a low-level language, meaning that theoretically, it cannot be beat; given unlimited time, you can optimize C++ code enough to beat anything. That's j
by skohan 4y ago
> C++ is a low-level language, meaning that theoretically, it cannot be beat; given unlimited time, you can optimize C++ code enough to beat anything.
That's just untrue right? You would have more room to optimize writing assembly directly?
- Santosh83 4y agoI guess that statement is comparing C++ with other high level languages. Not assembly. After all, one can drop down to assembly from any language. But "theoretically" is not interesting. What's more interesting is what is practically possible. Even Python can be made as fast as assembly by writing everything in the latter inside a Python shell, but those are unrealistic comparisons. Practically speaking C++ is difficult to beat, in terms of speed, from other languages at a similar level of abstraction.
- skohan 4y agoYeah but the point would be, if you can beat C++ with assembly, then theoretically there can exist a compiler for another language which can compile to that same assembly, meaning C++ isn't at the theoretical limit. Maybe it's a nitpick, but it gives me a little bit of pause to see a statement like this on a language website's page, since it seems to indicate a bit of a weak or sloppy understanding of computer science fundamentals.
- nine_k 4y agoHand-optimizing assembly becomes too hard for humans past certain size, which is not yet too large for LLVM, GCC, or ICC. OTOH Fortran (and, I suppose, something like APL / K / Q) can generate faster code than C++ because Fortran guarantees the absence of aliasing. In C or C++, aliasing precludes certain kinds of optimizations, and proving the absence of aliasing at a particular spot may be too time-consuming (if tractable at all) for the compiler to try.