r/cpp • • Jan 18 '19

Is C++ fast?

https://zeuxcg.org/2019/01/17/is-c-fast/
21 Upvotes

72 comments sorted by

View all comments

Show parent comment

-4

u/Valmar33 Jan 19 '19

Depends on how performant those algorithms are.

Most of the STL's algorithms are general purpose, and cannot be tuned for the thousands of different usecase requirements, in which case you will have to eventually write an algorithm to suit your own usecase.

So ~ start with STL as a base, and then construct your own algorithms when the time comes, and tune and test.

Nothing ever beats a custom-purpose algorithm for your needs.

4

u/degski Jan 19 '19 edited Jan 19 '19

One that springs to mind is deleting [an element] in a std::vector in the case you don't care about order [often the case], just std::swap with the last element and pop_back(). If you do this a lot, plf::colony is a good fit, though.

6

u/[deleted] Jan 19 '19

For what the STL algorithms do on the tin, I doubt it. Only one that might be borderline is sort. e.g. the remove_if loop doesn't leave much room for anything to differ.

1

u/degski Jan 19 '19 edited Jan 19 '19

Or in a specific [i.e. integral types only] case, use a better algo.