JDK7 introduces new sorting algorithms: dual pivot quicksort and "tim's merge sort". Evaluate on synthetic data and see what the difference is.
http://gdtoolbox.com/DualPivotQuicksort.pdf
–
I created a benchmark against sun-jdk1.7.0_ea_b104. The benchmark tried to compare "new" vs. "old" implementation of Collections.sort() first; on nearly-sorted strings, representing integers from 0..1000000:
benchmark ms linear runtime
LegacySort 39.5 ===
NewSort 25.3 ==
this turns out really well compared to IndirectSort:
benchmark ms linear runtime
IndirectMergeSort 63.7 ======
IndirectQuickSort 313.3 ==============================
LegacySort 39.5 ===
NewSort 25.3 ==
but there is a catch: that was nearly sorted data. The same benchmark, but executed on 1.6_20 shows hotspot improvements have been made as well, not only algorithmic improvements (I assume LegacySort didn't change between 1.6 and 1.7; haven't verified this):
benchmark ms linear runtime
IndirectMergeSort 63.5 =====
IndirectQuickSort 317.8 ==============================
LegacySort 53.3 =====
NewSort 53.2 =====
Very similar results from jrockit:
benchmark ms linear runtime
IndirectMergeSort 69.6 =====
IndirectQuickSort 396.9 ==============================
LegacySort 60.5 ====
NewSort 60.2 ====
vm: c:\java\jrmc-4.0.0-1.6.0\bin\java.exe
The second benchmark changed the scenario: I randomized the input so it wasn't nearly sorted and I changed Collections.sort() to Arrays.sort() calls to run on Integer[] arrays with a custom comparator, simulating IndirectSort's functionality. This yields, from 1.7:
benchmark ms linear runtime
IndirectMergeSort 785 ====================
IndirectQuickSort 918 =======================
LegacySort 1156 =============================
NewSort 1163 ==============================
Ok, much more sensible.
Conclusions: if data is nearly sorted and can be reordered, stick to Collections.sort(). If data is randomized and you don't want to reorder the input (for whatever reason), use IndirectSort.
Issue: HPPC-33 (migrated from JIRA), created by Dawid Weiss (@dweiss), resolved Mar 14 2011