4-15% speed-up in std::sort special case - is it worth the effort?

Gabriel Dos Reis gdr@integrable-solutions.net
Tue Oct 19 17:31:00 GMT 2010

On Wed, Aug 25, 2010 at 2:44 AM, Jaroslav Hajek <highegg@gmail.com> wrote:
> Hi all,
> I've been experimenting with sorting recently and I have noticed a
> possibility to slightly optimize the sorting of std::pair values using
> the default < operator. This is, I believe, a common usage case to
> retrieve sorting indices (better locality of reference than sorting
> via pointers). At least I usually do it that way :)
> The idea is simple: we know how the < operator for std::pairs looks
> like; basically it's
> x.first < y.first || (! (y.first < x.first) && x.second < y.second)

std::pair can be specialized (along with user defined comparators.)
How are you handling that?

More information about the Libstdc++ mailing list