summaryrefslogtreecommitdiffstats
path: root/benchmarks/helpers.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-11 16:34:56 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-11 16:34:56 +0000
commit278f416d08028bd175e1d6433739461f2168f4e2 (patch)
tree12492ebc5907744b2a4297228324fcda9ee2e40f /benchmarks/helpers.py
parentAdding upstream version 24.1.0. (diff)
downloadsqlglot-upstream/25.0.3.tar.xz
sqlglot-upstream/25.0.3.zip
Adding upstream version 25.0.3.upstream/25.0.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'benchmarks/helpers.py')
-rw-r--r--benchmarks/helpers.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/benchmarks/helpers.py b/benchmarks/helpers.py
new file mode 100644
index 0000000..bfb9821
--- /dev/null
+++ b/benchmarks/helpers.py
@@ -0,0 +1,28 @@
+import typing as t
+
+
+def border(columns: t.Iterable[str]) -> str:
+ columns = " | ".join(columns)
+ return f"| {columns} |"
+
+
+def ascii_table(table: list[dict[str, t.Any]]) -> str:
+ columns = []
+ for row in table:
+ for key in row:
+ if key not in columns:
+ columns.append(key)
+
+ widths = {column: max(len(column), 15) for column in columns}
+
+ lines = [
+ border(column.rjust(width) for column, width in widths.items()),
+ border(str("-" * width) for width in widths.values()),
+ ]
+
+ for row in table:
+ lines.append(
+ border(str(row[column]).rjust(width)[0:width] for column, width in widths.items())
+ )
+
+ return "\n".join(lines)