samples: dir sample data stack demo, renames
[urforth.git] / tools / show_wordname_hash_stats.f
blobb7022501b503b1a7519e6f183d459feca8ef148c
1 : bucket-count ( -- bkcount ) 1 wlist-hash-bits lshift ;
3 0 var word-count
4 0 value buckets
6 : count-bucket-items ( bkptr -- )
7 0 swap
8 begin
9 @ ?dup
10 while
11 swap 1+ swap
12 repeat
15 : show-stats ( vocid -- )
16 dup vocid->htable to buckets
17 dup vocid-hashed? ifnot 0 to buckets endif
19 endcr
20 ." VOC: " dup vocid.
22 word-count 0!
23 [: drop word-count 1+! false ;] foreach-word drop
25 ." -- " word-count @ . ." words, "
27 buckets if
28 0 0x7fff_ffff \ max and min in bucket
29 0 \ buckets used
30 bucket-count 0 do
31 i cells buckets + count-bucket-items
32 ?dup if
34 1+ \ update total used
35 rot r@ max
36 rot r@ min
37 rot
38 rdrop
39 endif
40 loop
41 ;; ( bkmin bkmax bkused )
42 nrot 2dup 2>r rot \ for average
43 0 .r ." /" bucket-count . ." buckets, " . ." min, " . ." max, average per bucket: "
44 \ show average
45 2r> + 2/ 0 .r cr
46 else
47 ." no hashtable\n"
48 endif
51 : all-vocs ( -- )
52 [: ( vocid -- endflag )
53 show-stats false
54 ;] foreach-voc drop
57 all-vocs
60 vocid-of forth show-stats
61 [IFDEF] c4s vocid-of c4s show-stats [ENDIF]
62 [IFDEF] prng vocid-of prng show-stats [ENDIF]
63 [IFDEF] disx86 vocid-of disx86 show-stats [ENDIF]
64 [IFDEF] asmx86 vocid-of asmx86 show-stats [ENDIF]
65 [IFDEF] asmx86:lexer vocid-of asmx86:lexer show-stats [ENDIF]
66 [IFDEF] asmx86:instructions vocid-of asmx86:instructions show-stats [ENDIF]
67 [IFDEF] asm-labman vocid-of asm-labman show-stats [ENDIF]
68 [IFDEF] asm-meta vocid-of asm-meta show-stats [ENDIF]
71 bye