vector-space.scm 3.8 KB

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