~/talk

“A Little Order: Delving into the STL sorting algorithms”

Talkat CppCon 2018 · 2018-09-23..09-28· [compilers-and-language-design]
links:none on file
slides:none on file

Benchmarks on Quick‑Bench and local compilers show finding the median of a 1,000,000 element vector with std::nth_element plus std::sort is three times faster than std::partial_sort for that case. Tests repeat across GCC, libc++ and MSVC, varying N and k. Analysis of STL source shows partial_sort is implemented with heap_select followed by heapsort and is tuned for very small k, while nth_element uses introselect (quickselect then heapselect) so complexity and pivot behavior explain the counterintuitive timings. Use partial_sort for tiny k in huge N, otherwise prefer nth_element + sort.

AI-written summary · about

  1. 0:00Introduction to STL sorting
  2. 1:07Sorting algorithms overview
  3. 5:23Investigating performance differences
  4. 9:25Testing with multiple compilers
  5. 10:31Benchmarking with varying sizes
  6. 14:08When to use partial_sort
  7. 14:32Diving into the code
  8. 19:00Introsort and insertion sort
  9. 21:52Understanding partial_sort
  10. 25:27Key takeaways and conclusion
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.