space.scm 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. ; Part of Scheme 48 1.9. See file COPYING for notices and license.
  2. ; Authors: Richard Kelsey, Jonathan Rees, Mike Sperber, Marcus Crestani
  3. (define length-procedures
  4. (do ((i (- stob-count 1) (- i 1))
  5. (l '() (cons (eval `(lap *length ()
  6. (protocol 1 (push template))
  7. (stack-ref 1)
  8. (stored-object-length
  9. ,(enumerand->name i stob))
  10. (push)
  11. (literal 2)
  12. (push)
  13. (arithmetic-shift)
  14. (return))
  15. (interaction-environment))
  16. l)))
  17. ((< i 0) l)))
  18. (define (space)
  19. (collect)
  20. (display " pure impure total") (newline)
  21. (display " count bytes count bytes count bytes")
  22. (newline)
  23. (let loop ((i 0)
  24. (p-count-total 0)
  25. (p-bytes-total 0)
  26. (i-count-total 0)
  27. (i-bytes-total 0))
  28. (if (< i stob-count)
  29. (begin
  30. (collect)
  31. (let ((xs (find-all i))
  32. (length (list-ref length-procedures i)))
  33. (let loop2 ((j (- (vector-length xs) 1))
  34. (p-count 0)
  35. (i-count 0)
  36. (p-bytes 0)
  37. (i-bytes 0))
  38. (if (< j 0)
  39. (begin (report1 (enumerand->name i stob)
  40. p-count p-bytes
  41. i-count i-bytes)
  42. (loop (+ i 1)
  43. (+ p-count-total p-count)
  44. (+ p-bytes-total p-bytes)
  45. (+ i-count-total i-count)
  46. (+ i-bytes-total i-bytes)))
  47. (if (immutable? (vector-ref xs j))
  48. (loop2 (- j 1)
  49. (+ p-count 1)
  50. i-count
  51. (+ p-bytes (+ 4 (length (vector-ref xs j))))
  52. i-bytes)
  53. (loop2 (- j 1)
  54. p-count
  55. (+ i-count 1)
  56. p-bytes
  57. (+ i-bytes (+ 4 (length (vector-ref xs j))))))))))
  58. (report1 'total
  59. p-count-total p-bytes-total
  60. i-count-total i-bytes-total))))
  61. (define (report1 name p-count p-bytes i-count i-bytes)
  62. (write-padded name 26)
  63. (write-padded p-count 10)
  64. (write-padded p-bytes 10)
  65. (write-padded i-count 10)
  66. (write-padded i-bytes 10)
  67. (write-padded (+ p-count i-count) 10)
  68. (write-padded (+ p-bytes i-bytes) 11)
  69. (newline))
  70. (define least-byte-type (enum stob string))
  71. (define (write-padded x pad)
  72. (let ((s (if (symbol? x)
  73. (symbol->string x)
  74. (number->string x))))
  75. (display (make-string (- pad (string-length s)) #\space))
  76. (display s)))
  77. (define (record-space . pred-option)
  78. (collect)
  79. (let ((pred (if (null? pred-option) (lambda (x) #t) (car pred-option)))
  80. (rs (find-all (enum stob record)))
  81. (a '()))
  82. (do ((i (- (vector-length rs) 1) (- i 1)))
  83. ((< i 0)
  84. (for-each (lambda (z)
  85. (write-padded (cadr z) 7)
  86. (write-padded (* (caddr z) 4) 7)
  87. (display " ")
  88. (write (car z))
  89. (newline))
  90. (sort-list a (lambda (z1 z2)
  91. (> (caddr z1) (caddr z2))))))
  92. (let* ((r (vector-ref rs i))
  93. (probe (assq (record-ref r 0) a)))
  94. (if (pred r)
  95. (if probe
  96. (begin (set-car! (cdr probe) (+ (cadr probe) 1))
  97. (set-car! (cddr probe) (+ (caddr probe)
  98. (+ 1 (record-length r)))))
  99. (set! a (cons (list (record-ref r 0) 1 (+ 1 (record-length r)))
  100. a))))))))
  101. (define (vector-space . pred-option)
  102. (collect)
  103. (let ((pred (if (null? pred-option) (lambda (x) #t) (car pred-option)))
  104. (vs (find-all (enum stob vector))))
  105. (let ((e-count 0)
  106. (e-bytes 0)
  107. (t-count 0)
  108. (t-bytes 0)
  109. (b-count 0)
  110. (b-bytes 0)
  111. (v-count 0)
  112. (v-bytes 0)
  113. (l-count 0)
  114. (l-bytes 0)
  115. (o-count 0)
  116. (o-bytes 0))
  117. (let loop ((i (- (vector-length vs) 1)))
  118. (if (< i 0)
  119. (let ((fz (lambda (k b what)
  120. (write-padded k 7)
  121. (write-padded b 7)
  122. (display what)
  123. (newline))))
  124. (fz t-count t-bytes " table buckets")
  125. (fz e-count e-bytes " table entries")
  126. (fz b-count b-bytes " bindings")
  127. (fz v-count v-bytes " environment info")
  128. (fz l-count l-bytes " lexical environments")
  129. (fz o-count o-bytes " other"))
  130. (let* ((v (vector-ref vs i))
  131. (len (vector-length v))
  132. (bytes (* (+ len 1) 4)))
  133. (cond ((not (pred v)))
  134. ((and (= len 3)
  135. (bucket? (vector-ref v 2)))
  136. (set! e-count (+ e-count 1))
  137. (set! e-bytes (+ e-bytes bytes)))
  138. ((and (= len 3)
  139. (location? (vector-ref v 1)))
  140. (set! b-count (+ b-count 1))
  141. (set! b-bytes (+ b-bytes bytes)))
  142. ((vector-every bucket? v)
  143. (set! t-count (+ t-count 1))
  144. (set! t-bytes (+ t-bytes bytes)))
  145. ((or (and (= len 4)
  146. (integer? (vector-ref v 0))
  147. (list? (vector-ref v 3)))
  148. (vector-every symbol? v))
  149. (set! v-count (+ v-count 1))
  150. (set! v-bytes (+ v-bytes bytes)))
  151. ((and (> len 1)
  152. (or (vector? (vector-ref v 0))
  153. (integer? (vector-ref v 0))))
  154. (set! l-count (+ l-count 1))
  155. (set! l-bytes (+ l-bytes bytes)))
  156. (else
  157. ;;(if (= (remainder i 197) 0)
  158. ;; (begin (write v) (newline)))
  159. (set! o-count (+ o-count 1))
  160. (set! o-bytes (+ o-bytes bytes))))
  161. (loop (- i 1))))))))
  162. (define (bucket? x)
  163. (or (eq? x #f)
  164. (vector? x)))
  165. (define (vector-every pred v)
  166. (let loop ((i (- (vector-length v) 1)))
  167. (if (< i 0)
  168. #t
  169. (if (pred (vector-ref v i))
  170. (loop (- i 1))
  171. #f))))
  172. (define (mutable? x) (not (immutable? x)))
  173. ; Print a random sampling of mutable pairs.
  174. (define (pair-space)
  175. (collect)
  176. (let ((vs (find-all (enum stob pair))))
  177. (let loop ((i (- (vector-length vs) 1))
  178. (j 0))
  179. (if (>= i 0)
  180. (let ((x (vector-ref vs i)))
  181. (if (mutable? x)
  182. (begin (if (= (remainder j 293) 0)
  183. (begin (limited-write x (current-output-port) 4 4)
  184. (newline)))
  185. (loop (- i 1) (+ j 1)))
  186. (loop (- i 1) j)))))))