[Haskell-cafe] using Map rather than FiniteMap

S. Alexander Jacobson alex at alexjacobson.com
Wed Jan 26 12:21:20 EST 2005

On Tue, 25 Jan 2005, David Menendez wrote:
> Does having 'zipped' at the top level mean that the program is keeping
> the entire 100,000-element list in memory?

I don't know, but I tested with zipped at the top, 
in the where, and it appears to make no 
performance or memory difference.

> Also, would performance improve if you used Map.fromList? How about
> Map.fromAscList?

HUGE IMPROVEMENT.  The old code had maximum 
residency of 11Mb and running time of 41s.  The 
code using Map.fromList has max. residency of 
6.4Mb and running time of 5.2s!

I guess foldlStrict is HUGELY more efficient than 
than foldr. (Why isn't it in the prelude?) But 
even using foldrStrict (fromList), we are still 
using 60 bytes per item and have ~30 bytes 
unaccounted for.  Any hints?

   import qualified Map

   main = print $ length  $ Map.keys theMap
 	zipped =zip [1..] [1..100000]::[(Int,Int)]
 	theMap = Map.fromList zipped

S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com

> S. Alexander Jacobson writes:
>> After actually running the correct test, I am
>> still getting semi-ridiculous space behavior
>> (6k/pair)!
>>     import qualified Map
>>     zipped =zip [1..] [1..100000]::[(Int,Int)]
>>     untup f (x,y) = f x y
>>     produce = foldr (untup Map.insert) Map.empty zipped
>>     fm = length  $ Map.keys produce
>>     main = print $ fm
> Two questions I'm currently too lazy to investigate myself:
> -- 
> David Menendez <zednenem at psualum.com> | "In this house, we obey the laws
> <http://www.eyrie.org/~zednenem>      |        of thermodynamics!"

More information about the Haskell-Cafe mailing list