From 232f62b450b9ebab05ba555b837a29e5453894c6 Mon Sep 17 00:00:00 2001 From: Andy C Date: Sun, 24 Nov 2024 23:17:49 -0500 Subject: [PATCH] [pretty] Fixed baseline metrics For hnode_t counts and doc_t counts --- asdl/format.py | 28 +++++++++++++++------------- display/pp_hnode.py | 1 + display/pretty-benchmark.sh | 31 ++++++++++++++++++++++++++----- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/asdl/format.py b/asdl/format.py index c2193a5a1..55b64e27e 100644 --- a/asdl/format.py +++ b/asdl/format.py @@ -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) @@ -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 @@ -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()) @@ -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 diff --git a/display/pp_hnode.py b/display/pp_hnode.py index b51a89c77..d5cb3cc5b 100644 --- a/display/pp_hnode.py +++ b/display/pp_hnode.py @@ -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 diff --git a/display/pretty-benchmark.sh b/display/pretty-benchmark.sh index 39ede262f..1757ad4d6 100755 --- a/display/pretty-benchmark.sh +++ b/display/pretty-benchmark.sh @@ -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