Program slower with local definitions

2006-09-05 Thread Michael Marte

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
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: Program slower with local definitions

2006-09-05 Thread Rene de Visser
Michael Marte [EMAIL PROTECTED] schrieb im 
Newsbeitrag news:[EMAIL PROTECTED]
 Hello *,

 I noticed a five percent speed up by making local definitions global.
Maybe the global defintions are monomorphic, and the local defintions
are polymorphic. You could evaluate the types of the global types and
apply them to the local definitions to see if that then gives the same 
result.

(just guessing).

Rene. 



___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


RE: Program slower with local definitions

2006-09-05 Thread Simon Peyton-Jones
That's odd.  Making things more global can reduce optimisation
opportunities, but making things ore local should not.  You can say
-ddump-simpl to get an idea of what the differences are.  

If you can make a smallish repo case, I'll take a look, though perhaps
not before ICFP.

Simon

| -Original Message-
| From: [EMAIL PROTECTED]
[mailto:glasgow-haskell-users-
| [EMAIL PROTECTED] On Behalf Of Michael Marte
| Sent: 05 September 2006 17:40
| To: glasgow-haskell-users@haskell.org
| Subject: Program slower with local definitions
| 
| 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
| ___
| Glasgow-haskell-users mailing list
| Glasgow-haskell-users@haskell.org
| http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users