5 ms·
> safe languages are more useful on complex projects that in simple projects, but complex projects suffer more from performance degradation I don't think that'
by vmchale 6y ago
> safe languages are more useful on complex projects that in simple projects, but complex projects suffer more from performance degradation
I don't think that's true. C is often slower than C++ because of how inlining works, plus some domains (e.g. compilers) it's best to just use a GC language from the get-go.
- iainmerrick 6y agoC is often slower than C++ because of how inlining works Hang on, you’re cutting a few corners there! It’s easy to use inline functions in C too. Are you thinking of C++ templates, and the fact that e.g. std::sort is faster than qsort because it directly calls an inlined comparison function rather than a function pointer? That’s true, although it’s possible to achieve similar performance levels in C via hand-rolled data structures or macro hackery. I’ll grant you that the efficient C++ code is more idiomatic and likely safer. On the other hand, idiomatic C code is likely smaller when compiled, which can be important for performance too. I don’t believe “C is often slower than C++” is true in general.
- jstimpfle 6y agostd::sort is the poster child that is supposed to demonstrate the power of C++ templates. When in fact it is awkward to use (as an infrequent user of C++, why can't I never seem to remember how to wrap / make the comparison object?) and more importantly, sort performance is most often completely irrelevant to the performance of a program. And when it's not irrelevant, it's almost 100% certain that std::sort is not the right thing to use. Where it matters, it's probably possible to examine the context a little more closely and come up with a custom sort that runs in O(n) or at least faster than std::sort.
- cozzyd 6y agoYeah, the real poster-child for C++ performance should be something like Eigen
- Koshkin 6y agoOr, you could just call std::sort and be done with it. (And, oh, by the way, it is faster than qsort - templated code often is.)
- jstimpfle 6y agoYou haven't read my comment at all.
- clappski 6y agoAdding custom comparators is trivial with lambdas; std::sort( begin( c ), end( c ), []( const auto& lhs, const auto& rhs ) { /* some comparison impl for the value_type */ } ); Same for everything that take a comparator in <algorithm>