nth_element + sort versus partial_sort

S

Scott Meyers

At http://wordaligned.org/articles/top-ten-percent , Thomas Guest shows
how he found that running nth_element followed by sort produced results
*much* faster than simply running partial_sort. I ran the test myself,
and I got the same kinds of results he did. I've mentioned this to
others, and some have been motivated to run the test themselves.
They've been as astonished as me at the results.

I recently stumbled across partial_sort in stl; fwiw,
std:partial_sort( A, A + sqrt(N), A + N ) is ~ 10 times faster than
std:sort
on my old mac ppc, even for N 100.
Also fwiw, nth_element alone is ~ twice as slow as partial_sort --
odd.

What are others' experiences with and comments about using nth_element
followed by sort instead of partial_sort to sort the top part of some
range of values? For purposes of discussion, assume that random access
iterators are available.

Thanks,

Scott
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top