1 | #!/usr/bin/env bash
|
2 | #
|
3 | # Usage:
|
4 | # data_lang/pretty-benchmark.sh <function name>
|
5 |
|
6 | set -o nounset
|
7 | set -o pipefail
|
8 | set -o errexit
|
9 |
|
10 | # Only show real time
|
11 | TIMEFORMAT='%R'
|
12 | # User time is also interesting
|
13 | # TIMEFORMAT='%U'
|
14 |
|
15 | # It takes much longer to print than to parse.
|
16 | #
|
17 | # Output example:
|
18 | #
|
19 | # benchmarks/testdata/configure-coreutils - parsing only, then parsing and printing
|
20 | # AST not printed.
|
21 | # 0.129
|
22 | #
|
23 | # 108811544 # <-- This is 109 MB of output text!
|
24 | # 3.679
|
25 |
|
26 | # 2024-11
|
27 | # 74292325 # 74 MB
|
28 | # 2.668
|
29 |
|
30 | # NEW Wadler printer!
|
31 |
|
32 |
|
33 | compare() {
|
34 | local osh=_bin/cxx-opt/osh
|
35 | ninja $osh
|
36 |
|
37 | #for file in benchmarks/testdata/conf*; do
|
38 | for file in benchmarks/testdata/configure; do
|
39 | echo ---
|
40 | echo "$file - parsing only, then parsing and printing"
|
41 |
|
42 | # Don't print at all. configure-coreutils is 136 ms.
|
43 | time $osh --ast-format none --tool syntax-tree $file
|
44 | echo
|
45 |
|
46 | # Print the whole thing
|
47 | time $osh --ast-format text --tool syntax-tree $file | wc --bytes
|
48 | echo
|
49 |
|
50 | # Print abbreviated
|
51 | time $osh --tool syntax-tree $file | wc --bytes
|
52 | echo
|
53 |
|
54 | done
|
55 | }
|
56 |
|
57 | gc-stats() {
|
58 | local osh=_bin/cxx-opt/osh
|
59 | #local osh=_bin/cxx-asan/osh
|
60 | ninja $osh
|
61 |
|
62 | # We should be doing some big GCs here
|
63 | export _OILS_GC_VERBOSE=1
|
64 |
|
65 | # 41 KB file
|
66 | for file in benchmarks/testdata/functions; do
|
67 | # 615K file
|
68 | #for file in benchmarks/testdata/configure; do
|
69 |
|
70 | # THIS FILE MAKES MY COMPUTER LOCK UP SOMETIMES!
|
71 | # 1.7 MB file
|
72 | #for file in benchmarks/testdata/configure-coreutils; do
|
73 |
|
74 | local fmt=__perf
|
75 | echo "___ parsing and pretty printing $file"
|
76 | time OILS_GC_STATS=1 $osh --ast-format $fmt --tool syntax-tree $file | wc --bytes
|
77 | echo
|
78 |
|
79 | continue
|
80 |
|
81 | # even after adding GC
|
82 | # - max RSS is 878 MB, on configure
|
83 | # - other the other hand, the output is just 30 MB (30,370,809 bytes)
|
84 | # - max RSS is 2,386 MB, on configure-coreutils
|
85 | /usr/bin/time --format '*** elapsed %e, max RSS %M' -- \
|
86 | $osh --ast-format $fmt --tool syntax-tree $file | wc --bytes
|
87 | echo
|
88 |
|
89 | echo "OLD printer"
|
90 | # Compare against OLD printer
|
91 | time OILS_GC_STATS=1 osh --ast-format text --tool syntax-tree $file | wc --bytes
|
92 |
|
93 | continue
|
94 | echo ---
|
95 |
|
96 | # 585K objects allocated, 16 MB
|
97 | echo "$file - parsing only"
|
98 | time OILS_GC_STATS=1 $osh --ast-format none --tool syntax-tree $file
|
99 | echo
|
100 |
|
101 | # 14M allocated, 450 MB! Geez!
|
102 | echo "$file - parsing, pretty print abbreviated"
|
103 | time OILS_GC_STATS=1 $osh --tool syntax-tree $file | wc --bytes
|
104 | echo
|
105 |
|
106 | # 31 M allocated, 1 GB! Gah
|
107 | echo "$file - parsing, pretty print full"
|
108 | time OILS_GC_STATS=1 $osh --ast-format text --tool syntax-tree $file | wc --bytes
|
109 | echo
|
110 |
|
111 | done
|
112 | }
|
113 |
|
114 | readonly -a FILES=(
|
115 | benchmarks/testdata/{functions,configure}
|
116 |
|
117 | # This file is known to lock up my Debian machine! It seems to go into a
|
118 | # swap loop.
|
119 | # configure-coreutils
|
120 | )
|
121 |
|
122 | count-small() {
|
123 | # Python
|
124 | bin/osh --ast-format __perf --tool syntax-tree -c 'echo hi'
|
125 | return
|
126 |
|
127 | local osh=_bin/cxx-opt/osh
|
128 | #local osh=_bin/cxx-dbg/osh
|
129 | ninja $osh
|
130 |
|
131 | /usr/bin/time --format '*** elapsed %e, max RSS %M' -- \
|
132 | $osh --ast-format __perf --tool syntax-tree -c 'echo hi'
|
133 | }
|
134 |
|
135 | counters() {
|
136 | local osh=_bin/cxx-opt/osh
|
137 | #local osh=_bin/cxx-dbg/osh
|
138 | ninja $osh
|
139 |
|
140 | #export OILS_GC_STATS=1
|
141 |
|
142 | for file in "${FILES[@]}"; do
|
143 | echo "=== parsing and pretty printing $file"
|
144 | echo
|
145 |
|
146 | /usr/bin/time --format '*** elapsed %e, max RSS %M' -- \
|
147 | $osh --ast-format __perf --tool syntax-tree $file | wc --bytes
|
148 | done
|
149 | }
|
150 |
|
151 | max-rss() {
|
152 | local osh=_bin/cxx-opt/osh
|
153 | ninja $osh
|
154 |
|
155 | for file in "${FILES[@]}"; do
|
156 | echo "___ parsing and pretty printing $file"
|
157 | echo
|
158 |
|
159 | /usr/bin/time --format '*** elapsed %e, max RSS %M' -- \
|
160 | $osh --ast-format text --tool syntax-tree $file | wc --bytes
|
161 | done
|
162 | }
|
163 |
|
164 |
|
165 | test-abbrev() {
|
166 | local osh=_bin/cxx-opt/osh
|
167 | ninja $osh
|
168 |
|
169 | local file=benchmarks/testdata/configure-coreutils
|
170 |
|
171 |
|
172 | time $osh --ast-format text --tool syntax-tree $file > _tmp/pretty-text-1.txt
|
173 | time $osh --ast-format text --tool syntax-tree $file > _tmp/pretty-text-2.txt
|
174 |
|
175 | # object IDs are not the same!
|
176 | time $osh --tool syntax-tree $file > _tmp/pretty-abbrev.txt
|
177 |
|
178 | wc --bytes _tmp/pretty-*
|
179 | }
|
180 |
|
181 | float-demo() {
|
182 | ### Test of tabular floats - not a test or a benchmark right now
|
183 |
|
184 | # Note: this could change if we change how floats are printed, e.g. strtof
|
185 | # vs. strtod.
|
186 |
|
187 | local ysh=_bin/cxx-asan/ysh
|
188 | ninja $ysh
|
189 |
|
190 | #ysh=bin/ysh
|
191 |
|
192 | $ysh -c '
|
193 | var L = []
|
194 | for i in (1 .. 200) {
|
195 | call L->append(i/30)
|
196 | }
|
197 | = L
|
198 | '
|
199 | }
|
200 |
|
201 | "$@"
|