login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

Submitted by : (unknown) at: 2007-11-17T22:33:21-08:00 (17 years ago)
Name :
Axiom Version :
Category : Severity : Status :
Optional subject :  
Optional comment :

On 6/13/07, Alasdair McAndrew wrote:

Wondering about nice little numeric exercises to help introduce Axiom to a small group of students, I attempted to sum the first 20000 reciprocals:

fricas
(1) -> )set message time on
reduce(+,[1.0/i for i in 1..20000])

\label{eq1}10.4807282172 \<u> 29327571(1)
Type: Float
fricas
Time: 0.11 (EV) + 0.02 (OT) = 0.13 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?

On 6/16/07, Waldek Hebisch wrote:

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)))
(define-function 'LIST2REFVEC #'LIST2VEC)
lisp
   Your user access level is compiler and this command is therefore not
      available. See the )set userlevel command for more information.

fricas
reduce(+,[1.0/i for i in 1..20000])

\label{eq2}10.4807282172 \<u> 29327571(2)
Type: Float
fricas
Time: 0.10 (EV) = 0.11 sec

fricas
[i for i in 1..20000];
Type: List(PositiveInteger?)
fricas
Time: 0.04 (EV) = 0.04 sec

thank you Waldek --billpage, Sat, 16 Jun 2007 14:25:41 -0500 reply
Category: Aldor Library Compiler => Axiom Interpreter Status: open => fix proposed




  Subject: (replying)   Be Bold !!
  ( 15 subscribers )  
Please rate this page: