[Haskell-cafe] Why doesn't GHC use the Hugs definition of splitAt to avoid traversing the first part of the list twice?

Richard Kelsall r.kelsall at millstream.com
Sat Apr 26 10:38:44 EDT 2008

Brandon S. Allbery KF8NH wrote:
> On Apr 26, 2008, at 9:02 , Richard Kelsall wrote:
>> I'm now wondering why my splitAtRK function in the following code
>> makes it run in 11 seconds given a parameter of 2500000 but it takes
>> 14 seconds when I change it to splitAt. Am I accidentally invoking
> It's somewhat unusual to build the standard libraries with -O2, I 
> think.  (It can be done but the build takes a very long time.)
> Also, 11 vs. 14 seconds seems not that much of a difference when you're 
> talking 2500000 items, especially given how inefficient Haskell lists 
> (Strings are lists) are.

Yes, well spotted. If I lower the compile level from -O2 to -O the
splitAtRK version takes 14.5 seconds vs 14 seconds for the built-in
version. Thank you. That solves the puzzle.

For the benchmarks I expect they use a default packaged GHC, I don't
imagine I could get them to use specially compiled libraries to bump
up the GHC score. Which gives an interesting dilemma of whether I
could get away with adding a small relevant snippet of library code
to the program in order to give it -O2 level compilation. I wonder
how much the other compilers optimise their library code.


More information about the Haskell-Cafe mailing list