vector-space.scm 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. ; Part of Scheme 48 1.9. See file COPYING for notices and license.
  2. ; Authors: Richard Kelsey, Jonathan Rees
  3. ; ,open architecture primitives low-level locations debug-data syntactic
  4. ; July 5th
  5. ;total number of 3-vectors: 10896
  6. ;probably table entries: 10381
  7. ;symbol keys: 7363
  8. ;integer keys: 3018
  9. ;symbol values: 3793
  10. ;location values: 2062
  11. ;pair values: 1723
  12. ;operator values: 989
  13. ;debug-data values: 1208
  14. ;transform values: 510
  15. ; pair 4039 48468
  16. ; symbol 1067 8536
  17. ; vector 4477 124132
  18. ; closure 1541 18492
  19. ; location 807 9684
  20. ; port 2 40
  21. ; ratio 0 0
  22. ; record 579 16732
  23. ; continuation 6 136
  24. ; extended-number 0 0
  25. ; template 985 23916
  26. ; weak-pointer 33 264
  27. ; external 0 0
  28. ;unused-d-header1 0 0
  29. ;unused-d-header2 0 0
  30. ; string 1207 19338
  31. ; code-vector 986 51097
  32. ; double 0 0
  33. ; bignum 0 0
  34. ; total 15729 320835
  35. (define (analyze-3-vectors)
  36. (collect)
  37. (let ((vs (find-all (enum stob vector)))
  38. (total 0)
  39. (table-entries 0)
  40. (symbol-keys 0)
  41. (int-keys 0)
  42. (symbols 0)
  43. (locations 0)
  44. (debug-datas 0)
  45. (pairs 0)
  46. (operators 0))
  47. (set! *foo* '())
  48. (vector-for-each
  49. (lambda (v)
  50. (if (= (vector-length v) 3)
  51. (let ((x (vector-ref v 2)))
  52. (set! total (+ total 1))
  53. (cond ((or (vector? x) (eq? x #f))
  54. (set! table-entries (+ table-entries 1))
  55. (let ((key (vector-ref v 0)))
  56. (cond ((symbol? key)
  57. (set! symbol-keys (+ symbol-keys 1)))
  58. ((integer? key)
  59. (set! int-keys (+ int-keys 1)))))
  60. (let ((val (vector-ref v 1)))
  61. (cond ((symbol? val)
  62. (set! symbols (+ symbols 1)))
  63. ((location? val)
  64. (set! locations (+ locations 1)))
  65. ((pair? val)
  66. (set! pairs (+ pairs 1)))
  67. ((transform? val)
  68. (set! operators (+ operators 1)))
  69. ((debug-data? val)
  70. (set! debug-datas (+ debug-datas 1)))
  71. (else (set! *foo* (cons v *foo*))))))))))
  72. vs)
  73. (display "total number of 3-vectors: ") (write total) (newline)
  74. (display "probably table entries: ") (write table-entries) (newline)
  75. (display "symbol keys: ") (write symbol-keys) (newline)
  76. (display "integer keys: ") (write int-keys) (newline)
  77. (display "symbol values: ") (write symbols) (newline)
  78. (display "location values: ") (write locations) (newline)
  79. (display "pair values: ") (write pairs) (newline)
  80. (display "transform values: ") (write operators) (newline)
  81. (display "debug-data values: ") (write debug-datas) (newline)))
  82. (define *foo* '())
  83. (define (bar)
  84. (collect)
  85. (vector-size-histogram (find-all (enum stob vector))))
  86. (define (vector-size-histogram vs)
  87. (write (vector-length vs)) (display " vectors") (newline)
  88. (let ((n 0))
  89. (vector-for-each (lambda (v)
  90. (if (eq? v vs) 'foo
  91. (if (> (vector-length v) n)
  92. (set! n (vector-length v)))))
  93. vs)
  94. (display "longest: ") (write n) (newline)
  95. (let ((hist (make-vector (+ n 1) 0)))
  96. (vector-for-each (lambda (v)
  97. (let ((l (vector-length v)))
  98. (vector-set! hist l (+ (vector-ref hist l) 1))))
  99. vs)
  100. (let loop ((i 0))
  101. (if (< i n)
  102. (let ((m (vector-ref hist i)))
  103. (if (> m 0)
  104. (begin (write-padded i 6)
  105. (write-padded m 7)
  106. (write-padded (* (+ (* i m) 1) 4) 7)
  107. (newline)))
  108. (loop (+ i 1))))))))
  109. (define (write-padded x pad)
  110. (let ((s (if (symbol? x)
  111. (symbol->string x)
  112. (number->string x))))
  113. (do ((i (- pad (string-length s)) (- i 1)))
  114. ((<= i 0) (display s))
  115. (write-char #\space))))
  116. (define (vector-for-each proc v)
  117. (let ((z (vector-length v)))
  118. (do ((i (- z 1) (- i 1)))
  119. ((< i 0) #f)
  120. (if (not (vector-unassigned? v i))
  121. (proc (vector-ref v i))))))