Skip to content

Latest commit

 

History

History
172 lines (141 loc) · 15.5 KB

File metadata and controls

172 lines (141 loc) · 15.5 KB

IList Sorting Performance Benchmarks

Unity Helpers ships several custom sorting algorithms for IList<T> that cover different trade-offs between adaptability, allocation patterns, and stability. This page gathers context and benchmark snapshots so you can choose the right algorithm for your workload and compare results across operating systems.

Algorithm Cheatsheet

Algorithm Stable? Best For Reference
Ghost Sort No Mixed workloads that benefit from adaptive gap sorting and few allocations Upstream project by Will Stafford Parsons (public repository currently offline)
Meteor Sort No Almost-sorted data where gap shrinking beats plain insertion sort Upstream project by Will Stafford Parsons (public repository currently offline)
Pattern-Defeating QuickSort No General-purpose quicksort with protections against worst-case inputs pdqsort by Orson Peters
Grail Sort Yes Large datasets where stability + low allocations matter GrailSort
Power Sort Yes Partially ordered data that benefits from adaptive run detection PowerSort (Munro & Wild)
Tim Sort Yes General-purpose stable sorting with abundant natural runs Wikipedia - Timsort
Jesse Sort No Data with long runs or duplicates where dual patience piles shine JesseSort
Green Sort Yes Sustainable stable merges that trim ordered prefixes greeNsort
Ska Sort No Branch-friendly partitioning on large unstable datasets Ska Sort
Ipn Sort No In-place adaptive quicksort scenarios needing robust pivots ipnsort write-up
Smooth Sort No Weak-heap hybrid that approaches O(n) for presorted data Smoothsort - Wikipedia
Block Merge Sort Yes Stable merges with √n buffer (WikiSort style) WikiSort
IPS⁴o Sort No Cache-aware samplesort with multiway partitioning IPS⁴o paper
Power Sort Plus Yes Enhanced run-priority merges inspired by Wild & Nebel PowerSort paper
Glide Sort Yes Stable galloping merges from the Rust glidesort research sort-research-rs
Flux Sort No Dual-pivot quicksort tuned for modern CPUs sort-research-rs
Insertion Sort Yes Tiny or nearly sorted collections where O(n²) is acceptable Wikipedia - Insertion sort

What does “stable” mean? Stable sorting algorithms preserve the relative order of elements that compare as equal. This matters when items carry secondary keys (e.g., sorting people by last name but keeping first-name order deterministic). Unstable algorithms can reshuffle equal entries, which is usually fine for numeric keys but can break deterministic pipelines.

Heads up: The original Ghost Sort repository was formerly hosted on GitHub under wstaffordp/ghostsort, but it currently returns 404. The Unity Helpers implementation remains based on that source; we will relink if/when an official mirror returns.

Dataset Scenarios

  • Sorted – ascending integers, verifying best-case behavior.
  • Nearly Sorted (2% swaps) – deterministic neighbor swaps introduce light disorder to expose adaptive optimizations.
  • Shuffled (deterministic) – Fisher–Yates shuffle using a fixed seed for reproducibility across runs and machines.

Each benchmark sorts a fresh copy of the dataset once and reports wall-clock duration. If a cell still shows pending, re-run the benchmark suite to collect fresh data for that algorithm/dataset size.

Run the IListSortingPerformanceTests.Benchmark test inside Unity’s Test Runner to refresh the tables below. Results automatically land in the section that matches the current operating system.

Windows (Editor/Player)

Last updated 2026-04-22 22:08 UTC on Windows 11 (10.0.26200) 64bit

Times are single-pass measurements in milliseconds (lower is better). n/a indicates the algorithm was skipped for the dataset size.

Sorted

List Size Ghost Meteor Pattern-Defeating QuickSort Grail Power Insertion Tim Jesse Green Ska Ipn Smooth Block IPS4o Power+ Glide Flux
1000.004 ms0.001 ms0.001 ms0.001 ms0.001 ms0.001 ms0.001 ms0.093 ms0.001 ms0.006 ms0.001 ms0.002 ms0.001 ms0.001 ms0.001 ms0.001 ms0.002 ms
1,0000.022 ms0.024 ms0.006 ms0.006 ms0.005 ms0.005 ms0.005 ms1.16 ms0.006 ms0.095 ms0.007 ms0.016 ms0.005 ms0.031 ms0.004 ms0.005 ms0.026 ms
10,0000.261 ms0.343 ms0.063 ms0.068 ms0.040 ms0.052 ms0.038 ms14.4 ms0.059 ms1.36 ms0.063 ms0.161 ms0.045 ms0.513 ms0.040 ms0.040 ms0.341 ms
100,0003.04 ms4.46 ms0.632 ms0.639 ms0.393 msn/a0.379 ms192 ms0.591 ms17.6 ms0.654 ms1.64 ms0.438 ms6.22 ms0.390 ms0.383 ms4.38 ms

Nearly Sorted (2% swaps)

List Size Ghost Meteor Pattern-Defeating QuickSort Grail Power Insertion Tim Jesse Green Ska Ipn Smooth Block IPS4o Power+ Glide Flux
1000.001 ms0.002 ms0.002 ms0.001 ms0.002 ms0.001 ms0.001 ms0.118 ms0.001 ms0.006 ms0.001 ms0.002 ms0.001 ms0.002 ms0.002 ms0.002 ms0.002 ms
1,0000.020 ms0.024 ms0.028 ms0.007 ms0.015 ms0.006 ms0.012 ms1.21 ms0.006 ms0.096 ms0.025 ms0.016 ms0.006 ms0.039 ms0.022 ms0.014 ms0.027 ms
10,0000.253 ms0.342 ms0.371 ms0.069 ms0.228 ms0.055 ms0.168 ms14.3 ms0.062 ms1.38 ms0.340 ms0.167 ms0.060 ms0.595 ms0.361 ms0.159 ms0.352 ms
100,0003.10 ms4.54 ms4.47 ms0.726 ms3.27 msn/a2.25 ms186 ms0.642 ms17.3 ms4.09 ms1.69 ms0.548 ms7.03 ms5.16 ms2.14 ms4.40 ms

Shuffled (deterministic)

List Size Ghost Meteor Pattern-Defeating QuickSort Grail Power Insertion Tim Jesse Green Ska Ipn Smooth Block IPS4o Power+ Glide Flux
1000.008 ms0.006 ms0.005 ms0.006 ms0.007 ms0.015 ms0.009 ms0.041 ms0.006 ms0.008 ms0.006 ms0.010 ms0.005 ms0.005 ms0.022 ms0.010 ms0.006 ms
1,0000.144 ms0.120 ms0.084 ms0.099 ms0.104 ms1.28 ms0.132 ms0.442 ms0.101 ms0.127 ms0.091 ms0.179 ms0.083 ms0.101 ms0.422 ms0.143 ms0.094 ms
10,0001.95 ms1.75 ms1.14 ms1.35 ms1.43 ms128 ms1.48 ms5.54 ms1.36 ms1.72 ms1.23 ms2.56 ms1.13 ms1.44 ms5.94 ms1.69 ms1.38 ms
100,00028.4 ms23.8 ms14.4 ms17.3 ms17.3 msn/a19.1 ms69.7 ms17.1 ms22.3 ms15.1 ms32.2 ms14.3 ms18.3 ms75.0 ms22.1 ms17.1 ms

macOS

Pending — run the IList sorting benchmark suite on macOS to capture results.

Linux

Pending — run the IList sorting benchmark suite on Linux to capture results.

Other Platforms

Pending — run the IList sorting benchmark suite on the target platform to capture results.