Skip to content

Commit

Permalink
[data_lang] Add pretty printing benchmark
Browse files Browse the repository at this point in the history
It takes much longer to print than to parse.  See snippet in shell
script.
  • Loading branch information
Andy C committed Mar 6, 2024
1 parent 015034d commit 82f15ff
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
45 changes: 45 additions & 0 deletions data_lang/pretty-benchmark.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash
#
# Usage:
# data_lang/pretty-benchmark.sh <function name>

set -o nounset
set -o pipefail
set -o errexit

# Only show real time
TIMEFORMAT='%R'
# User time is also interesting
# TIMEFORMAT='%U'

# It takes much longer to print than to parse.
#
# Output example:
#
# benchmarks/testdata/configure-coreutils - parsing only, then parsing and printing
# AST not printed.
# 0.129
#
# 108811544 # <-- This is 109 MB of output text!
# 3.679

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

for file in benchmarks/testdata/*; do
echo ---
echo "$file - parsing only, then parsing and printing"

# Don't print at all. configure-coreutils is 136 ms.
time $osh --ast-format none --tool syntax-tree $file
echo

# Print the whole thing
time $osh --ast-format text --tool syntax-tree $file | wc --bytes
echo

done
}

"$@"
18 changes: 18 additions & 0 deletions data_lang/pretty_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python2
"""
pretty_test.py
"""

import unittest

from data_lang import pretty # module under test


class PrettyTest(unittest.TestCase):

def testFoo(self):
print(pretty)


if __name__ == '__main__':
unittest.main()
18 changes: 18 additions & 0 deletions tools/fmt_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python2
"""
fmt_test.py
"""

import unittest

from tools import fmt # module under test


class FmtTest(unittest.TestCase):

def testFoo(self):
print(fmt)


if __name__ == '__main__':
unittest.main()

0 comments on commit 82f15ff

Please sign in to comment.