[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: map-array



At 14:12 12/11/92 -0500, Guillaume Cartier wrote:
><---
>| Based on the Code of Bill St.Clair for faster-climits I tried to write a
>| general map-array function,
>| both a mcl specific and a portable version.
>| 
>| Then I compared this construct to mapc for sequences
>| 
>| To my surprise, the mapping an array was slower than mapping over a list.
>| Am I missing something ?
>--->
>
>Yes!
>
>It is true that access to a specific element of an array in generaly faster
>than access to a specific element of a list. But, in this case, we are not accessing elements individualy but mapping over the whole structure.
>
>Mapping over an array involves accessing every element individualy (each
>time having to do at least a multiplication and an addition) where as
>mapping over a list involves simple pointer indirections which are very
>fast.

Although what Guillaume says is true, the AREF can all be in-line
if you pass an array that uses that part of your map-array-ccl macro.
You made an array with an element type of FIXNUM, which MCL upgrades to
(signed-byte 32). This is NOT a simple-vector, so you end up going
out of line for the AREF. If you let the element type default to T,
you get faster performance (I timed the following on a IIci):

(defun initialize (n)
  (setq *long-sequence* nil)
  ; **** Note the element type default to T ****
  (setq *array-like-sequence* (make-array (list n n)))
  (dotimes (y n)
    (dotimes (x n)
      (let ((wert (random 2000)))
        (push wert *long-sequence*)
        (setf (aref *array-like-sequence* y x) wert))))
 )

#|
(initialize 200)

(without-interrupts (time (test-sequence)))
(TEST-SEQUENCE) took 1353 milliseconds (1.353 seconds) to run.
Of that, 1 milliseconds (0.001 seconds) were spent in The Cooperative Multitasking Experience.
 32 bytes of memory allocated.
(MIN 0 MAX 1999)

(without-interrupts (time (TEST-ARRAY-CCL)))
(TEST-ARRAY-CCL) took 1331 milliseconds (1.331 seconds) to run.
 32 bytes of memory allocated.
(MIN 0 MAX 1999)

(without-interrupts (time (test-array-portable)))
(TEST-ARRAY-PORTABLE) took 1894 milliseconds (1.894 seconds) to run.
 64 bytes of memory allocated.
(MIN 0 MAX 1999)
|#