On Mon, 25 Aug 2008, Tobia Conforto wrote:
Elf wrote:
(define a
(alist->hash-table
(let loop ((i 0))
(if (fx= 250000 i)
'()
(cons (cons (random 500000)
(random 500000))
(loop (fx+ 1 i)))))
=))
for an improvement in time (surprisingly), use
(define a
(alist->hash-table
(let loop ((i 0)
(r '()))
(if (fx= 250000 i)
r
(loop (fx+ 1 i)
(cons (cons (random 500000)
(random 500000))
r))))
=))
...there are a lot more minor GCs this way
Why is it surprising that the tail-recursive version performs better? And
why do you say it has more GC? Isn't it supposed to produce less garbage?
well, i say it has more cause thats what the stats said :) the reason why
it would be more in large cases like this is because it has to repeatedly
copy a large structure in the iterative-tail-recursion version, whereas
in the stacking recursion it just has to copy the frames onto the heap
every so often.
-elf
_______________________________________________
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users