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
"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
"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