🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.lisp.mcl
Article #610

Re: map-array

#610
From: Bill St. Clair
Date: Mon, 14 Dec 1992 21:07
59 lines
2613 bytes
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)
|#
Technical Details
Message-ID: <9212142001.AA01433@cambridge.apple.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!apple!cambridge.apple.com!bill@cambridge.apple.com

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!apple!cambridge.apple.com!bill@cambridge.apple.com
From: bill@cambridge.apple.com (Bill St. Clair)
Newsgroups: comp.lang.lisp.mcl
Subject: Re: map-array
Message-ID: <9212142001.AA01433@cambridge.apple.com>
Date: 14 Dec 92 21:07:14 GMT
Sender: info-mcl-request@cambridge.apple.com
Lines: 59
Approved: comp.lang.lisp.mcl@Cambridge.Apple.C0M