<div dir="ltr"><div class="gmail_extra">Some comments:<br></div><div class="gmail_extra">1) Never run benchmarks inside DrRacket (I suspect this is what you did because the reported times are high)<br></div><div class="gmail_extra">
2) Why do you include the garbage collections in the time measurment? That's probably not what you want to measure (plus the gc should before the calls)<br></div><div class="gmail_extra">3) The need to call `reverse` in `list-incr/acc` is sufficient alone to blow the recorded times (looks like it's what you were saying).<br>
<br></div><div class="gmail_extra">Here is I think a more appropriate benchmark, summing the values in a list:<br><br>#lang racket<br>(define (list-sum/direct lst)<br> (cond<br> [(empty? lst) 0]<br> [else (+ (car lst)<br>
(list-sum/direct (cdr lst)))]))<br><br>(define (list-sum/acc lst (acc 0))<br> (cond<br> [(empty? lst) acc]<br> [else (list-sum/acc (cdr lst)<br> (+ (car lst) acc))]))<br><br>(define huge-list<br>
(build-list 50000 identity))<br><br>(collect-garbage)<br>(collect-garbage)<br>(collect-garbage)<br>(time<br> (for ([i 2000])<br> (list-sum/direct huge-list)))<br><br>; cpu time: 6440 real time: 6481 gc time: 100<br><br>
(collect-garbage)<br>(collect-garbage)<br>(collect-garbage)<br>(time<br> (for ([i 2000])<br> (list-sum/acc huge-list)))<br><br>; cpu time: 1508 real time: 1537 gc time: 8<br><br></div><div class="gmail_extra">Here the tail recursion version is 4x faster.<br>
<br></div><div class="gmail_extra">Laurent<br></div><div class="gmail_extra"><br><br></div></div>