-
-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[data_lang] Add pretty printing benchmark
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
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
"$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |