From: Oleg
Subject: tiny CMUCL benchmark
Date: 
Message-ID: <3d5b5ad8.0211151423.59be90e8@posting.google.com>
I'm trying to get the following little function to run as fast as
possible:

(defun f (s r)
  (proclaim '(optimize speed))
  (let ((a (make-array (list s) :element-type 'double-float)))
  (dotimes (n s) (setf (aref a n) n))
  (dotimes (n s) (print (aref a n)))
  (dotimes (i r)
    (dotimes (j s) (setf (aref a j) (cos (aref a j)))))))

It basically creates a 0, 1, 2... (s - 1) array and applies
elementwise cos to it r times. What I'm getting is about 3-4 times
slower than C, and there seems to be noticeable GCing, as if (setf
(aref a j) (cos (aref a j))) does heap allocation. Any ideas?

Oleg

From: Wade Humeniuk
Subject: Re: tiny CMUCL benchmark
Date: 
Message-ID: <QQeB9.3135$bh1.341705@news1.telusplanet.net>
"Oleg" <············@myrealbox.com> wrote in message
·································@posting.google.com...
> I'm trying to get the following little function to run as fast as
> possible:
>
> (defun f (s r)
>   (proclaim '(optimize speed))
>   (let ((a (make-array (list s) :element-type 'double-float)))
>   (dotimes (n s) (setf (aref a n) n))
>   (dotimes (n s) (print (aref a n)))
>   (dotimes (i r)
>     (dotimes (j s) (setf (aref a j) (cos (aref a j)))))))
>
> It basically creates a 0, 1, 2... (s - 1) array and applies
> elementwise cos to it r times. What I'm getting is about 3-4 times
> slower than C, and there seems to be noticeable GCing, as if (setf
> (aref a j) (cos (aref a j))) does heap allocation. Any ideas?
>
> Oleg

Try

(defun f (s r)
  (declare (optimize (speed 3) (safety 0) (debug 0) #+lispworks(float 0)))
  (let ((a (make-array s :element-type 'double-float)))
    (print (loop for n of-type fixnum from 0 below s
                 collect (setf (svref a n) n)))
    (dotimes (i r)
      (declare (fixnum i))
      (dotimes (j s)
        (declare (fixnum j))
        (setf (svref a j) (cos (svref a j)))))))

Wade
From: Wade Humeniuk
Subject: Re: tiny CMUCL benchmark
Date: 
Message-ID: <1gfB9.3144$bh1.347072@news1.telusplanet.net>
"Wade Humeniuk" <····@nospam.nowhere> wrote in message
··························@news1.telusplanet.net...
> Try
>
> (defun f (s r)
>   (declare (optimize (speed 3) (safety 0) (debug 0) #+lispworks(float 0)))
>   (let ((a (make-array s :element-type 'double-float)))
>     (print (loop for n of-type fixnum from 0 below s
>                  collect (setf (svref a n) n)))
>     (dotimes (i r)
>       (declare (fixnum i))
>       (dotimes (j s)
>         (declare (fixnum j))
>         (setf (svref a j) (cos (svref a j)))))))

Brutal, I should have tested first with safety and debug on.  Crushes LWW.

New version
(defun f (s r)
  (declare (optimize (speed 3) (safety 0) (debug 0) #+lispworks(float 0)))
  (let ((a (make-array s :element-type 'double-float
                       :initial-contents (loop for n from 0 below s collect (float n 1.0d0)))))
    (print a)
    (dotimes (i r)
      (declare (fixnum i))
      (dotimes (j s)
        (declare (fixnum j))
        (setf (aref a j) (cos (aref a j)))))))

Wade