optimizing std sort in libc
play

Optimizing std::sort in libc++ Aditya Kumar Divya Shanmughan - PowerPoint PPT Presentation

Optimizing std::sort in libc++ Aditya Kumar Divya Shanmughan Issues with std::sort (libc++) Worst case clang-libc++ O(N^2) vs. gcc-libstdc++ O(NlogN) Time complexity (worst case*) 40 gcc-libstdc++ 35 clang-libcxx 30 25 Time


  1. Optimizing std::sort in libc++ Aditya Kumar Divya Shanmughan

  2. Issues with std::sort (libc++) • Worst case – clang-libc++ O(N^2) vs. gcc-libstdc++ O(NlogN) Time complexity (worst case*) 40 gcc-libstdc++ 35 clang-libcxx 30 25 Time (seconds) 20 15 10 5 0 32 64 128 256 512 1024 2048 4096 8192 16384 32768 Data Size (Bytes) * https://bugs.llvm.org/show_bug.cgi?id=20837

  3. Sorting Algorithm in libc++ • Sorting algorithm currently implemented in libc++ uses quicksort • Worst Case Complexity – O(N^2) • Recursion Stack Space – O(logN)

  4. Modifications done • Convert to introsort* – Sorting technique, which begins with quicksort and switches to heapsort after recursion reaches a threshold – Worst case complexity of O(NlogN) • Eliminate recursion – Replaced memory Intensive recursive calls with stack – std::stack uses std::deque, which uses std::algorithm :( • Improved worst case time complexity by a factor of 10 – https://reviews.llvm.org/D36423 https://en.wikipedia.org/wiki/Introsort

  5. Sorting Results Plot (With std-benchmark) * https://github.com/hiraditya/std-benchmark

  6. Thank You

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend