[Haskell-beginners] State Transformer Confusion
Chris Pettitt
cpettitt at gmail.com
Wed Feb 24 21:04:02 EST 2010
Hello Haskell-Beginners,
I'm having a fair amount of difficulty understanding the ST monad. In
my basic experimentation I'm finding that I'm getting more heap
allocated with STUArray than with a regular Array, which is not what I
would expect.
I've attached a sample program that attempts to sum a list of Ints
into an array of length 1, using STUArray and UArray. The idea is
based loosely on http://www.haskell.org/haskellwiki/Monad/ST, but
using an array instead of an STRef.
I compile using these arguments: ghc -fforce-recomp -O2 -prof
-auto-all -caf-all --make sttest.hs
When I run the ST-based function (sumInPlace1), I get the following output:
./sttest +RTS -sstderr
1784293664
240,944,212 bytes allocated in the heap
35,448 bytes copied during GC
4,052 bytes maximum residency (1 sample(s))
12,332 bytes maximum slop
1 MB total memory in use (0 MB lost due to fragmentation)
Generation 0: 459 collections, 0 parallel, 0.00s, 0.00s elapsed
Generation 1: 1 collections, 0 parallel, 0.00s, 0.00s elapsed
INIT time 0.00s ( 0.00s elapsed)
MUT time 0.30s ( 0.31s elapsed)
GC time 0.00s ( 0.00s elapsed)
RP time 0.00s ( 0.00s elapsed)
PROF time 0.00s ( 0.00s elapsed)
EXIT time 0.00s ( 0.00s elapsed)
Total time 0.30s ( 0.31s elapsed)
%GC time 0.8% (1.2% elapsed)
Alloc rate 804,910,126 bytes per MUT second
Productivity 99.0% of total user, 96.5% of total elapsed
While with the Array based function (sumInPlace2), I get the following output:
./sttest +RTS -sstderr
1784293664
173,627,572 bytes allocated in the heap
22,596 bytes copied during GC
3,920 bytes maximum residency (1 sample(s))
12,464 bytes maximum slop
1 MB total memory in use (0 MB lost due to fragmentation)
Generation 0: 333 collections, 0 parallel, 0.00s, 0.00s elapsed
Generation 1: 1 collections, 0 parallel, 0.00s, 0.00s elapsed
INIT time 0.00s ( 0.00s elapsed)
MUT time 0.14s ( 0.15s elapsed)
GC time 0.00s ( 0.00s elapsed)
RP time 0.00s ( 0.00s elapsed)
PROF time 0.00s ( 0.00s elapsed)
EXIT time 0.00s ( 0.00s elapsed)
Total time 0.15s ( 0.15s elapsed)
%GC time 1.3% (1.9% elapsed)
Alloc rate 1,200,569,571 bytes per MUT second
Productivity 98.3% of total user, 94.7% of total elapsed
One additional point of confusion for me: when I run either function
with +RTS -hc and use hp2ps I get an empty graph. I've seen these
tools work quite well before, so I suspect I'm doing something wrong
now.
Thanks,
Chris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sttest.hs
Type: application/octet-stream
Size: 589 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/beginners/attachments/20100224/8665b2ea/sttest.obj
More information about the Beginners
mailing list