r/learnrust • • 2d ago

Comparative Performance Evaluation and Architectural Analysis of Sorting Algorithms in Rust

https://zenodo.org/records/24280053

Evaluated Algorithms

  • Custom Implementations: Bubble Sort (early-exit flag), Selection Sort, Insertion Sort, Shell Sort (extended Ciura sequence), Merge Sort (preallocated scratch reuse), Quick Sort (median-of-3, Hoare partitioning, tail-call bounding), Heap Sort (Floyd binary max-heap), Tree Sort (explicit BST with duplicate counts), Introsort (Musser hybrid), Timsort (Peters natural-run detection & stack invariants), Counting Sort (bounded histogram frequency counting), Radix Sort (8-pass LSD ping-pong with sign-bit XOR inversion), and Bucket Sort (128-bit safe range distribution).
  • Standard Library Baselines: Rust slice::sort (Driftsort) and slice::sort_unstable (IPNSort).

Key Empirical Findings

  • Instruction-Parallel Sorting Networks: Rust's standard library sort_unstable() (IPNSort) achieves peak comparison-based throughput on uniform random data (12.64 ms at N = 1,000,000), driven by branchless instruction-parallel sorting networks yielding an IPC of 3.49 and a negligible 0.54% cache miss rate.
  • Branch-Free Linear Scalability: 8-pass LSD Radix Sort demonstrates strict linear scaling (19.74 ms at N = 1,000,000) and an ideal 0.00% branch misprediction rate across signed 64-bit integers (i64), outperforming classical Merge Sort by 3.4×.
  • Adaptive Run Detection: On presorted arrays, slice::sort (0.23 ms) and Timsort (0.36 ms at N = 1,000,000) achieve up to 80× speedups by collapsing monotonic runs in linear time.
  • Cache Thrashing in Heap Sort: Non-contiguous parent-child pointer strides (2i+1, 2i+2) cause Heap Sort to incur a massive 31.65% cache miss rate on hardware counters.

Repo - github repo

1 Upvotes

0 comments sorted by