The generic sort algorithm in .Net does not perform well on sorting strings. The reason for that is that it performs too many character comparisons while comparing strings.
There is a better algorithm described by Prof. Robert Sedgewick called multikey quicksort. Sedgewick is known for his developer friendly books on algorithms and his approach to empirically study algorithm performance. In the case of soring strings, Sedgewick provides a reference implementation of string sort in C:Sedgewick's Reference Implementation of Sorting Strings
His implementation is quite hard to understand but achieves excellent performance.
Fast String Sort in C# and F# - CodeProject
No comments:
Post a Comment