[racket] streams, recursion and running out of memory
Thanks Rodolfo,
I did some further experiments which confirm your results. I noticed that
results vary quite a bit run to run so I ran several times from clean and
took the median:
prime-pi/acc 4000000 with original make-coroutine:
cpu time: 2808 real time: 2879 gc time: 1000
prime-pi/acc 4000000 w/ stream-ref precall with original make-coroutine:
cpu time: 3214 real time: 3245 gc time: 1342
prime-pi/acc 4000000 with alternate make-coroutine:
cpu time: 2886 real time: 2996 gc time: 856
prime-pi/acc 4000000 w/ stream-ref precall and with alternate
make-coroutine:
cpu time: 2901 real time: 2968 gc time: 1078
prime-pi 4000000 w/ stream-ref precall and with original make-coroutine:
cpu time: 5054 real time: 5063 gc time: 2810
It is still interesting that prime-pi performed so badly with the alternate
coroutine (and without the precall cludge). I reran it this way and had to
break the process when it ran over 5 minutes. BTW, with the cludge and the
alternate make-coroutine it ran fine, yesterday's results for that case are
bogus as I believe that after a bad run you need to actually bring down
DrRacket (not just hit the run button) in order to clean up memory.
I think we also confirm that you have a better machine than I :-)
-joe
On Wed, Feb 22, 2012 at 8:40 AM, Rodolfo Carvalho <rhcarvalho at gmail.com>wrote:
> Hello Joe,
>
>
> 2012/2/22 Joe Gilray <jgilray at gmail.com>
>
>> Hi Matthew,
>>
>> Thanks for your help. I really can't even pretend to understand the
>> make-coroutine code but this is what I'm seeing:
>>
>> Original make-coroutine, without stream-ref pre-call => out of memory
>> (1GB) when running (prime-pi 500000)
>>
>
>
> I tried to run your code here and I also get out of memory in the first
> case.
>
>
>
>
>> Original make-coroutine, with stream-ref pre-call => runs (prime-pi
>> 500000) in about .4 sec
>>
>
>
> Just as a reference to the other results, here it gives: cpu time: 328
> real time: 328 gc time: 94.
>
>
>
>
>> Alternate make-coroutine, with or without stream-ref pre-call => runs
>> (prime-pi 500000) in about 28 sec
>>
>>
> With stream-ref pre-call: cpu time: 343 real time: 344 gc time: 78
> Without: cpu time: 19609 real time: 19719 gc time: 9172
>
>
>
>
> I changed `prime-pi' into `prime-pi/acc' as below and then I got the best
> results:
>
> (define (prime-pi/acc n)
> (let loop-count ([candidate-stream primes]
> [sum 0])
>
> (if (> (stream-first candidate-stream) n)
> sum
> (loop-count (stream-rest candidate-stream) (add1 sum)))))
>
>
> With original make-coroutine: cpu time: 234 real time: 235 gc time: 0
> With Matthew's make-coroutine: cpu time: 187 real time: 187 gc time: 0
>
>
>
> All measurements made from within DrRacket using (time (prime-pi 500000))
> or (time (prime-pi/acc 500000)).
>
> []'s
>
> Rodolfo
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120222/2250da0f/attachment.html>