home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / lisp / 2944 < prev    next >
Encoding:
Internet Message Format  |  1992-11-19  |  3.9 KB

  1. Xref: sparky comp.lang.lisp:2944 comp.lang.lisp.mcl:1684
  2. Newsgroups: comp.lang.lisp,comp.lang.lisp.mcl
  3. Path: sparky!uunet!spool.mu.edu!agate!boulder!cambridge.apple.com!apple!ames!elroy.jpl.nasa.gov!usc!sol.ctr.columbia.edu!ira.uka.de!sbusol.rz.uni-sb.de!coli.uni-sb.de!mp-mac10.coli.uni-sb.de!espen
  4. From: espen@coli.uni-sb.de (Espen J. Vestre)
  5. Subject: Re: remove
  6. Message-ID: <722551894.1477@news.Colorado.EDU>
  7. Lines: 83
  8. Sender: news
  9. Organization: Computerlinguistik, Universitaet des Saarlandes
  10. References: <HALTRAET.92Nov20091121@monsun.si.no>
  11. Distribution: co
  12. Date: 23 Nov 92 09:12:55 GMT
  13. Approved: news
  14. X-Note1: mail msgid was <1eq7anINNejt@coli-gate.coli.uni-sb.de>
  15. X-Note2: message-id generated by recnews
  16. Lines: 83
  17.  
  18. In article <HALTRAET.92Nov20091121@monsun.si.no> Hallvard Tr{tteberg,
  19. haltraet@monsun.si.no writes:
  20. >Time-ing shows a big difference:
  21. >
  22. >(DOTIMES (A 1000) (DOTIMES (B 8) (FASTER-REMOVE B '(1 2 3 4 5 1 2 3 4
  23. >5)))) took 2421 milliseconds (2.421 seconds) to run.
  24. >Of that, 117 milliseconds (0.117 seconds) were spent in The
  25. >Cooperative Multitasking Experience.
  26. > 240000 bytes of memory allocated.
  27. >NIL
  28. >? 
  29. >(DOTIMES (A 1000) (DOTIMES (B 8) (REMOVE B '(1 2 3 4 5 1 2 3 4 5))))
  30. >took 6966 milliseconds (6.966 seconds) to run.
  31. >Of that, 376 milliseconds (0.376 seconds) were spent in The
  32. >Cooperative Multitasking Experience.
  33. > 640000 bytes of memory allocated.
  34. >NIL
  35. >
  36. >I know my function isn't as general as remove since it only works on
  37. >lists and doesn't take all those arguments. But I feel remove should
  38. >be optimized for the simplest cases and also should try to cons as
  39. >little as possible. As the results show, faster-remove (or should it
  40. >be called low-consing-remove) is far better when it comes to consing.
  41. >
  42.  
  43. [hei Hallvard, hyggelig aa se at det fortsatt programmeres i MCL paa SI!]
  44.  
  45. Hallvard,
  46.  
  47. Your function can definitely be faster for several purposes, but because
  48. it isn't tail-recursive, it's not as general in its applicability as
  49. REMOVE: It doesn't work for large lists.
  50. In the following example, the value of TSTLIST is the list
  51.   (10000 9999 ... 2 1):
  52.  
  53. ? (room)
  54. There are at least 12185032 bytes of available RAM.
  55.  
  56.                   Total Size            Free               Used
  57. Mac Heap:       972552 (949K)       361152 (352K)       611400 (598K)
  58. Lisp Heap:    12607488 (12312K)     11823880 (11546K)       788320 (769K)
  59.  (Static):      528384 (516K)
  60. Stacks:         208952 (204K)
  61. ? (progn (time (remove 5000 tstlist)) t)
  62. (REMOVE 5000 TSTLIST) took 69 milliseconds (0.069 seconds) to run.
  63.  80016 bytes of memory allocated.
  64. T
  65. ? (progn (time (faster-remove 5000 tstlist)) t)
  66. > Error: Stack overflow.
  67. > While executing: FASTER-REMOVE
  68. > Type Command-. to abort.
  69. See the RestartsU menu item for further choices.
  70. 1 > 
  71.  
  72. For shorter lists, but larger than in your example, your function shows a
  73. memory, but no time gain (egc is not used, btw).  The following example
  74. is your own example scaled by a factor of 100, i.e., TSTLIST is set to (1
  75. ... 500 1 ... 500):
  76.  
  77. ? (time (dotimes (X 800) (remove X tstlist)))
  78. (DOTIMES (X 800) (REMOVE X TSTLIST)) took 6078 milliseconds (6.078
  79. seconds) to run.
  80. Of that, 191 milliseconds (0.191 seconds) were spent in The Cooperative
  81. Multitasking Experience.
  82.  6400080 bytes of memory allocated.
  83. NIL
  84. ? (gc)
  85. NIL
  86. ? (time (dotimes (X 800) (faster-remove X tstlist)))
  87. (DOTIMES (X 800) (FASTER-REMOVE X TSTLIST)) took 6280 milliseconds (6.280
  88. seconds) to run.
  89. Of that, 200 milliseconds (0.200 seconds) were spent in The Cooperative
  90. Multitasking Experience.
  91.  2994000 bytes of memory allocated.
  92. NIL
  93.  
  94. --------------------------------------------------------------
  95. Espen J. Vestre,                          espen@coli.uni-sb.de
  96. Universitaet des Saarlandes,        
  97. Computerlinguistik, Gebaeude 17.2 
  98. Im Stadtwald,                          tel. +49 (681) 302 4501
  99. D-6600 SAARBRUECKEN, Germany           fax. +49 (681) 302 4351
  100. --------------------------------------------------------------
  101.