{
  "id": 19154480,
  "title": "A C++ Quicksort Faster Than std::sort",
  "url": "https://urgent.news/2026/11/09/a-c-quicksort-faster-than-std-sort",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-09T12:55:38.000Z",
  "source": {
    "name": "Lobsters",
    "slug": "lobsters",
    "url": "https://tiki.li/blog/about_blqsort"
  },
  "original_language": "en",
  "account": "blqsort is a highly efficient quicksort algorithm that outperforms std::sort, the standard sorting function in C++. This implementation utilizes branchless partitioning, sorting networks for small partitions, and robust pivot selection techniques. The algorithm is available on GitHub under the MIT license, and there's also a C version with multithreaded versions.\n\nThe benchmarks conducted on an Apple M1 system using Clang and an Intel i5-9300H system using GCC, both compiled with the -O3 option, demonstrate that blqsort significantly outperforms std::sort. On the M1, the multithreaded versions of blqsort are roughly three times faster than the single-threaded version.\n\nThe C implementation of blqsort sorts 50 million random doubles and handles already sorted, reverse-sorted inputs, and inputs with many duplicate keys efficiently. The execution times for these operations remain consistent between the C and C++ versions.\n\nTo prevent stack overflow issues caused by millions of recursive calls, tail call elimination is implemented. This involves replacing the second recursive call with a loop iteration, ensuring only the smaller partition is called recursively.\n\nHowever, this unfavorable partitioning behavior can lead to a worst-case time complexity of O(N²). By using the middle element as the pivot, this issue is mitigated. Additionally, introducing random pivot selection eliminates the risk of intentionally crafted data triggering the worst-case scenario. Choosing a pivot using the Lomuto partitioning scheme is efficient, but Hoare partitioning could offer better cache behavior on modern CPUs.\n\nWhile std::sort is generally faster, blqsort can still outperform it by using insertion sort for small partitions (up to around 20 elements) and employing sorting networks for optimal handling of each partition size. Overall, blqsort is a fast, versatile sorting algorithm that can rival or surpass std::sort in performance under specific conditions.",
  "summary": null,
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}