I recently started using <vector.h>
library and I was wondering, since all the operations are already implemented, IF the method of the sorting algorithm is the most efficient one. Everything runs perfect, there is no doubt, but should I worry about its performance?
If I want to sort up to 6-7 million numbers, should I implement my own sorting method using quick sort?
Best Answer
In most libraries,
std::sort
is implemented as an introsort, so unless you want to hurt worst-case performance (a lot), you almost certainly do not want to use Quicksort instead. My experience indicates that a home-rolled Quicksort will rarely improve performance noticeably anyway.The main reason to switch to something else would be to get something like stability (in which case you want
std::stable_sort
instead) or ability to work with data that won't fit in RAM (in which case you might want to look into STXXL), not for simple performance.