4 ms·
> Some of them are gross speed hacks, to cover up the slow speed that C++ causes. That’s certainly an interesting sentiment in 2012…
by saagarjha 7y ago
> Some of them are gross speed hacks, to cover up the slow speed that C++ causes.
That’s certainly an interesting sentiment in 2012…
- Koshkin 7y agoI don't know about 2012 but in general if used correctly C++ can often be faster than C due to the widespread inlining and the use of templates. (On the other hand, if one writes C++ as if it was Java - the code will be faster than Java's but often can be optimized further indeed.)
- bitwize 7y agoFor values of "used correctly" that, by the time you have mastered them in C++x, have changed completely in C++x+3.
- ahartmetz 7y agoIf it's about performance, that is usually not the case. In a few cases one could get a performance improvement using move semantics - most other new features are only about safety and convenience.
- tpolzer 7y agoIf you write C++ like it's Java, it will be slower, mostly for two reasons: - A C++ compiler cannot do speculative devirtualization. Which hurts if you split everything into small virtual functions. - If you are churning through lots of small allocations and aren't maxing all CPU cores, a garbage collector running in parallel is nearly free - unlike the bookkeeping your C++ deallocations have to go through.
- saagarjha 7y ago> A C++ compiler cannot do speculative devirtualization. Yes, it can! For example: https://godbolt.org/z/-JtSiJ https://godbolt.org/z/-JtSiJ
- userbinator 7y agodue to the widespread inlining and the use of templates On the other hand, this often causes a huge increase in code size, which means less code can fit in the instruction cache, and - even worse - when the system is on the verge of swapping, can make performance drop even faster. It's unfortunate that microbenchmarks often tend to favour such globally-inefficient code that's only slightly faster in isolation but bogs down the system as a whole. This article is related: https://news.ycombinator.com/item?id=18777735 https://news.ycombinator.com/item?id=18777735
- epx 7y agoIt might have been true by the 1990s due to gcc and even then it was grossly exaggerated by folks that led us to GObject