Hi, On Wed 05 Aug 2009 12:42, Andy Wingo <wi...@pobox.com> writes:
> The simple stack formulation of Ackermann's function is faster of > course: > > (define (A m n) > (if (= m 0) > (+ n 1) > (if (= n 0) > (A (- m 1) 1) > (A (- m 1) (A m (- n 1)))))) > > (A 3 9) completes in 1.45 seconds for me. > > Curiously, the letrec case takes more time: > > (define (A m n) > (let A ((m m) (n n)) > (if (= m 0) > (+ n 1) > (if (= n 0) > (A (- m 1) 1) > (A (- m 1) (A m (- n 1))))))) > > It should be faster, because we don't have to deref the toplevel > variable for A, but the compiler needs to be a little smarter. This > version takes about 1.6 seconds for me. I have fixed this issue. The letrec version now takes slightly less time than the version that recurses through the toplevel. >> % time guile -c '(begin (load-compiled "ack.go") (ackermann 3 9))' >> 48.728u 22.016s 1:10.75 99.9% 0+0k 0+0io 0pf+0w > > Indeed, I get similar times (44 seconds; presumably some of the > compilation fixes actually had an effect). This one now takes very, very marginally less time now (about a second) -- not much of an improvement, but I wanted to take care of it before taking catch / dynamic-wind. Thanks, Andy -- http://wingolog.org/