Program slower with local definitions

Michael Marte marte at pms.informatik.uni-muenchen.de
Tue Sep 5 12:40:19 EDT 2006


Hello *,

I noticed a five percent speed up by making local definitions global.

This is the first version with local definitions:

f = <some expression based on mySet>
     where
     mySet = foldl (flip Set.insert) Set.empty myList
     myList = <some constant list>

Then I moved mySet and myList to the top level which gave me the speed up.

Shouldn't both versions show the same behaviour with regard to run time? 
  Doesn't the compiler lift mySet and myList to top level automatically?
Are myList and mySet evaluated in every call to f when defined locally?

I am using ghc 6.4.2 on Windows XP.

Michael


More information about the Glasgow-haskell-users mailing list