title: Pre-sorting analysis algorithm?
body: <p>It's a well-known isssue with Quicksort that when the data set is in or almost in sort order, performance degrades horribly.  In this case, Insertion Sort, which is normally very slow, is easily the best choice.  The question is knowing when to use which.</p>
  
  <p>Is there an algorithm available to run through a data set, apply a comparison factor, and return a report on how close the data set is to being in sort order?  I prefer Delphi/Pascal, but I can read other languages if the example isn't overly complex.</p>