On 3/5/2011 4:34 AM, Barton Willis wrote:
> -----maxima-bounces at math.utexas.edu wrote: -----
>
>> Mostly like because you're running intepreted code, not compiled. Try
>> :lisp (compile '$hsum_cl) before running the test.
> Using GCL, hsum_cl is slow with or without compiling. I discovered this
> years ago. Maybe this has been fixed in GCL, but apparently the fix isn't
> in the GCL version used by Maxima. I think Maxima has its own function for
> rational number addition that is (sometimes) much faster than
> GCL's addition--for my test about 200 times faster.
>
> What this all means for deciding on CCL vs GCL for Windows is unclear. Maxima
> and GCL grew up together, so it's not surprising that they often work well
> together.
>
> (%i1) showtime : all$
>
> (%i2) :lisp(defun $hsum_cl (n) (let ((s 0)) (while (> n 0) (setq s (+ s (/ 1 n))) (decf n)) (to s)))
> $HSUM_CL
>
> (%i2) hsum_cl(10000)$
> Evaluation took 147.4300 seconds (147.4300 elapsed)
> (%i3) :lisp (compile '$hsum_cl)
>
> (%i3) hsum_cl(10000)$
> Evaluation took 100.4800 seconds (100.4800 elapsed)
>
> (%i4) hsum_max(n) := block([s : 0], while n> 0 do (s : s + 1/n, n : n-1),s)$
>
> (%i5) hsum_max(10000)$
> Evaluation took 0.5100 seconds (0.5100 elapsed)
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
In Allegro CL on a 3GHz windows machine, I ran the equivalent
(defun hsum(n)(do((i n (1- i))(s 0 (+ s (/ 1 i))))((= i 0) s)))
hsum
interpreted, (hsum 10000) took 0.828 sec, compiled, 0.734 sec.
compiled, it uses 0 cons cells.
With some declarations it runs a little faster.
RJF