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

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