STL Algorithms vs. Custom Algorithms

Hey, I'm working on a simple project, mostly for fun and practice. I wont go into details, but I have come to the point where I need a sorting algorithm.

Don't worry, I'm not asking for an opinion on which is most effective for what I want. I want to know if there would be any benefit of implementing my own custom algorithm vs. using the STL Algorithm for it (sort()).

Disregard benefits of practice for this. What I want to know is whether or not that using the STL sort would reduce performance significantly.

I'm assuming it would reduce performance, technically, but not significantly, because the program would have to retrieve the the sort() function from the library, which does use some resources.
closed account (o1vk4iN6)
Probably not, STL using many algorithms and chooses an appropriate one for the task. If you only use one algorithm then performance will be different based on what you are doing.
Probably the same or better unless you know of a very good sort algorithm for the data you will be sorting.
Retrieving the function gets done at the beginning of code execution if you're using dynamic linking. It won't have any effect on runtime performance.
STL has many sorting primitives, in addition to std::sort().

For instance,
Heap sort: std::make_heap(), std::sort_heap()
Merge Sort: std::merge(), std::inplace_merge()

In specific cases, where we can exploit the structure of the data set, a custom sort implementation could be faster; for instance a radix sort where k < log(n).

Topic archived. No new replies allowed.