[Haskell] Control.Monad.Writer as Python generator
ChrisK
chrisk at MIT.EDU
Fri Apr 15 12:03:01 EDT 2005
You are correct. Moand.Cont yield even runs without -O optimizing,
just slower:
Monad.Writer counts 10^9 zeros in 99 seconds (user time)
Monad.Cont counts 10^8 zero in 35 seconds user time.
So the writer is 3.5 times faster without '-O'
With -O
Monad.Writer counts 10^9 zeros in 105 seconds
Monad.Cont counts 10^8 zeros in 11 seconds, 10^9 zeros in 110 seconds.
So with '-O' they are the same speed. Nice.
Anyone have an idea why ghci can't garbage collect it?
Is this an actual bug or an innate quirk of the REPL ?
--
Chris
On Apr 15, 2005, at 12:43 AM, Cale Gibbard wrote:
> However, after compiling with optimisations turned on, there is no
> such problem with the continuation-based version, memory usage appears
> constant.
>
> - Cale
>
> On 4/14/05, ChrisK <chrisk at mit.edu> wrote:
>> Thanks for the Cont example, David. But...
>>
>> The MonadCont is clever and it works ... but then fails -- ghci does
>> not garbage collect and it blows up.
>> With the MonadCont version I can count up to 10^7 zeros:
>>
>> *Main> length $ take (10^7) zerosInf
>> 10000000
>> (26.20 secs, 0 bytes)
>>
>> But this increases RSIZE of ghc-6.4 to 165MB. The 10^8 version goes
>> to
>> swap space and I had to kill it. My original MonadWriter version does
>> not increase RSIZE when run (constant space), so the garbage
>> collection
>> must be working, and it is O(N) in the # of zeros counted:
>>
>> *Main> length $ take (10^7) zerosInf
>> 10000000
>> (1.22 secs, 0 bytes)
>> *Main> length $ take (10^8) zerosInf
>> 100000000
>> (10.05 secs, 0 bytes)
>> *Main> length $ take (10^9) zerosInf
>> 1000000000
>> (109.83 secs, 6 bytes)
>>
>> --
>> Chris
>>
More information about the Haskell
mailing list