I needed to implement a sorting method for my current project in order to sort an array of objects by a certain string property. As there is no sorting method for objects in Xojo I began toying around with several sorting algorithms (and I am anything but an expert on this).
In order to test my algorithms I splitted a document of 10797 words to a string array and let my sorting methods sort it. I tried the following methods (I am not sure if my English is appropriate for the following descriptions):
-
A simple bubble sort (for comparison)
-
A kind of selection sort, which loops through the original array and after each run appends the minimum element to a temporary array before removing it from the original array, so that the original array shrinks with each loop run
-
A recursive merge sort
-
A hybrid merge sort with an insertion sort firing if the length of the current sub array (is that a correct term for a part of an array?) is <= 10
-
Xojos Array.Sort method (for comparison)
The sorting durations were:
1. BubbleSort > 14962 milliseconds
2. My SelectionSort > 4450 milliseconds
3. MergeSort > 27 milliseconds
4. MergeSortHybrid > 24 milliseconds
5. Xojos Array.Sort > 10 milliseconds
As you can see, the hybrid merge sort is already quite fast (and surely fast enough for my needs) but still not half as fast as Xojos Array.Sort method.
So just out of curiosity: Which sorting algorithm does Xojo use for arrays?
Thanks in advance!