home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / lisp / mcl / 1837 < prev    next >
Encoding:
Text File  |  1992-12-14  |  2.5 KB  |  70 lines

  1. Path: sparky!uunet!stanford.edu!apple!cambridge.apple.com!bill@cambridge.apple.com
  2. From: bill@cambridge.apple.com (Bill St. Clair)
  3. Newsgroups: comp.lang.lisp.mcl
  4. Subject: Re: map-array
  5. Message-ID: <9212142001.AA01433@cambridge.apple.com>
  6. Date: 14 Dec 92 21:07:14 GMT
  7. Sender: info-mcl-request@cambridge.apple.com
  8. Lines: 59
  9. Approved: comp.lang.lisp.mcl@Cambridge.Apple.C0M
  10.  
  11. At 14:12 12/11/92 -0500, Guillaume Cartier wrote:
  12. ><---
  13. >| Based on the Code of Bill St.Clair for faster-climits I tried to write a
  14. >| general map-array function,
  15. >| both a mcl specific and a portable version.
  16. >| 
  17. >| Then I compared this construct to mapc for sequences
  18. >| 
  19. >| To my surprise, the mapping an array was slower than mapping over a list.
  20. >| Am I missing something ?
  21. >--->
  22. >
  23. >Yes!
  24. >
  25. >It is true that access to a specific element of an array in generaly faster
  26. >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.
  27. >
  28. >Mapping over an array involves accessing every element individualy (each
  29. >time having to do at least a multiplication and an addition) where as
  30. >mapping over a list involves simple pointer indirections which are very
  31. >fast.
  32.  
  33. Although what Guillaume says is true, the AREF can all be in-line
  34. if you pass an array that uses that part of your map-array-ccl macro.
  35. You made an array with an element type of FIXNUM, which MCL upgrades to
  36. (signed-byte 32). This is NOT a simple-vector, so you end up going
  37. out of line for the AREF. If you let the element type default to T,
  38. you get faster performance (I timed the following on a IIci):
  39.  
  40. (defun initialize (n)
  41.   (setq *long-sequence* nil)
  42.   ; **** Note the element type default to T ****
  43.   (setq *array-like-sequence* (make-array (list n n)))
  44.   (dotimes (y n)
  45.     (dotimes (x n)
  46.       (let ((wert (random 2000)))
  47.         (push wert *long-sequence*)
  48.         (setf (aref *array-like-sequence* y x) wert))))
  49.  )
  50.  
  51. #|
  52. (initialize 200)
  53.  
  54. (without-interrupts (time (test-sequence)))
  55. (TEST-SEQUENCE) took 1353 milliseconds (1.353 seconds) to run.
  56. Of that, 1 milliseconds (0.001 seconds) were spent in The Cooperative Multitasking Experience.
  57.  32 bytes of memory allocated.
  58. (MIN 0 MAX 1999)
  59.  
  60. (without-interrupts (time (TEST-ARRAY-CCL)))
  61. (TEST-ARRAY-CCL) took 1331 milliseconds (1.331 seconds) to run.
  62.  32 bytes of memory allocated.
  63. (MIN 0 MAX 1999)
  64.  
  65. (without-interrupts (time (test-array-portable)))
  66. (TEST-ARRAY-PORTABLE) took 1894 milliseconds (1.894 seconds) to run.
  67.  64 bytes of memory allocated.
  68. (MIN 0 MAX 1999)
  69. |#
  70.