Skip to content

Commit

Permalink
[pretty] Fixed baseline metrics
Browse files Browse the repository at this point in the history
For hnode_t counts and doc_t counts
  • Loading branch information
Andy C committed Nov 25, 2024
1 parent ee57252 commit 232f62b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 18 deletions.
28 changes: 15 additions & 13 deletions asdl/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ def _HNodeCount(h):

elif case(hnode_e.Array):
h = cast(hnode.Array, UP_h)
n = 0
n = 1 # 1 for this node
for child in h.children:
n += _HNodeCount(child)
return n

elif case(hnode_e.Record):
h = cast(hnode.Record, UP_h)
n = 0
n = 1 # 1 for this node
for field in h.fields:
n += _HNodeCount(field.val)

Expand Down Expand Up @@ -72,23 +72,23 @@ def _DocCount(d):

elif case(doc_e.Indent):
d = cast(doc.Indent, UP_d)
return _DocCount(d.mdoc.doc)
return 1 + _DocCount(d.mdoc.doc)

elif case(doc_e.Group):
d = cast(MeasuredDoc, UP_d)
return _DocCount(d.doc)
return 1 + _DocCount(d.doc)

elif case(doc_e.Flat):
d = cast(doc.Flat, UP_d)
return _DocCount(d.mdoc.doc)
return 1 + _DocCount(d.mdoc.doc)

elif case(doc_e.IfFlat):
d = cast(doc.IfFlat, UP_d)
return _DocCount(d.flat_mdoc.doc) + _DocCount(d.nonflat_mdoc.doc)
return 1 + _DocCount(d.flat_mdoc.doc) + _DocCount(d.nonflat_mdoc.doc)

elif case(doc_e.Concat):
d = cast(doc.Concat, UP_d)
n = 0
n = 1 # 1 for this node
for mdoc in d.mdocs:
n += _DocCount(mdoc.doc)
return n
Expand All @@ -105,9 +105,10 @@ def _HNodePrettyPrint(perf_stats, doc_debug, node, f, max_width=80):
log('___ HNODE COUNT %d', _HNodeCount(node))
log('')

log('___ GC: after hnode_t conversion')
mylib.PrintGcStats()
log('')
if 0:
log('___ GC: after hnode_t conversion')
mylib.PrintGcStats()
log('')

enc = pp_hnode.HNodeEncoder()
enc.SetUseStyles(f.isatty())
Expand All @@ -126,9 +127,10 @@ def _HNodePrettyPrint(perf_stats, doc_debug, node, f, max_width=80):
log('___ DOC COUNT %d', _DocCount(d))
log('')

log('___ GC: after doc_t conversion')
mylib.PrintGcStats()
log('')
if 0:
log('___ GC: after doc_t conversion')
mylib.PrintGcStats()
log('')

printer = pretty.PrettyPrinter(max_width) # max columns

Expand Down
1 change: 1 addition & 0 deletions display/pp_hnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def _Tabular(self, items, sep):
# style 3.

if len(items) == 0:
# TODO: this should be turned into "append nothing"
return AsciiText('')

max_flat_len = 0
Expand Down
31 changes: 26 additions & 5 deletions display/pretty-benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,38 @@ gc-stats() {
done
}

readonly -a FILES=(
benchmarks/testdata/{functions,configure,configure-coreutils}
)

counters() {
#local osh=_bin/cxx-opt/osh
local osh=_bin/cxx-dbg/osh
local osh=_bin/cxx-opt/osh
#local osh=_bin/cxx-dbg/osh
ninja $osh

# 615K file
for file in benchmarks/testdata/{functions,configure,configure-coreutils}; do
time $osh --ast-format __perf --tool syntax-tree $file | wc --bytes
for file in "${FILES[@]}"; do
echo "=== parsing and pretty printing $file"
echo

/usr/bin/time --format '*** elapsed %e, max RSS %M' -- \
$osh --ast-format __perf --tool syntax-tree $file | wc --bytes
done
}

max-rss() {
local osh=_bin/cxx-opt/osh
ninja $osh

for file in "${FILES[@]}"; do
echo "___ parsing and pretty printing $file"
echo

/usr/bin/time --format '*** elapsed %e, max RSS %M' -- \
$osh --ast-format text --tool syntax-tree $file | wc --bytes
done
}


test-abbrev() {
local osh=_bin/cxx-opt/osh
ninja $osh
Expand Down

0 comments on commit 232f62b

Please sign in to comment.