c++ - Does std::sort check if a vector is already sorted? -
i believe c++ standard std::sort not guarantee o(n) performance on list that's sorted. still, i'm wondering whether knowledge implementations of stl (gcc, msvc, etc) make std::is_sorted check before executing sort algorithm?
asked way, performance can 1 expect (without guarantees, of course) running std::sort on sorted container?
side note: posted some benchmarks gcc 4.5 c++0x enabled on blog. here's results:

implementations free use efficient sorting algorithm want highly implementation dependant
however have seen performance comparison of libstdc++ used on linux , against libc++ new c++ library developed apple/llvm. both these libraries efficient on sorted or reverse sorted data (much faster on random list) new library being considerable faster old , recognizing many more patterns.
to should consider doing own benchmarks.
Comments
Post a Comment