Wondering about nice little numeric exercises to help introduce Axiom to a small group of students, I attempted to sum the first 20000 reciprocals: axiom )set message time on
Type: Floataxiom Time: 0.19 (IN) + 1.72 (EV) + 0.12 (OT) = 2.03 sec This works, but is (I think) unreasonably slow; it takes over 21 seconds on my computer. The equivalent command in Maxima takes less than 1 second. Is there any way of encouraging Axiom to be faster here?
Bill Page wrote:: > On 6/15/07, Waldek Hebisch wrote: > > On my machine, I get the following (on the second run, to > > exclude time for loading): > > > > gcl sbcl sbcl > > interpreted compiled > > reduce(+,[1.0/i for i in 1..20000]) 8.70 1.76 0.17 > > [i for i in 1..20000]; 6.23 0.78 0.01 > > expand(1..20000); 0 0.004 0.01 > > > > Waldek, thank you very much for running this comparison! > > So, the conclusion might be that I was wrong: the slowness *is* > because of the way that Axiom interpreter runs this code in > interpreted mode in GCL, right? It could still be that this interpreted > Lisp code is not written in an optimal manner. > As I wrote, it turned out that GCL interpreter is quite fast. After using modified LIST2VEC function (patch below, applied to wh-sandbox), I get the following timings: reduce(+,[1.0/i for i in 1..20000]) 0.69 [i for i in 1..20000]; 0.09 It seems that now significant part of execution time goes into floating point arithmetic. lisp (defun LIST2VEC (list) (if (consp list) (let* ((len (length list)) (vec (make-array len))) (dotimes (i len) (setf (aref vec i) (pop list))) vec) (coerce list 'vector))) lisp ; compiling file "/var/zope2/var/LatexWiki/1444083084317242284-25px002.lisp" (written 06 JUL 2011 10:18:55 AM): axiom reduce(+,
Type: Floataxiom Time: 2.90 (EV) + 0.01 (OT) = 2.91 sec axiom [i for i in 1..20000]; Type: List(PositiveInteger?)axiom Time: 1.08 (EV) = 1.08 sec |

thank you Waldek--billpage, Sat, 16 Jun 2007 14:25:41 -0500 reply