Weird profiling behaviour

Koen Claessen koen@cs.chalmers.se
Wed, 26 Jun 2002 13:35:04 +0200 (MET DST)


Ketil Z. Malde wrote:

 | I have what I think is a really strange problem.  I
 | have a fair sized problem, which involves sorting a
 | data set, first on labels (which are Strings) and then
 | on scores (which are Ints).
 |
 | The strange thing is that string sorting is *vastly*
 | faster than int scoring!

Colin Runciman helpfully suggested:

 | Could it be that the string-comparison sort simply has
 | less sorting to do than the int-comparison sort?  The
 | default definition of sortBy uses insertion sort, so
 | if the string-sort input happens to be already sorted
 | it takes linear time and if the int-sort input happens
 | to be in reverse order it takes quadratic time.

Another reason might be that the ints in the list are not
evaluated yet; and sorting the list on the ints forces
evaluation of them which maybe takes time?

/Koen.