Skip to content

Commit

Permalink
Improve report output for copy pasting
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Jun 3, 2024
1 parent 7babfe9 commit d8c09b7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
4 changes: 4 additions & 0 deletions milabench/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ def build_matrix_bench(all_configs):

for name, bench_config in all_configs.items():
for k, v in expand_matrix(name, bench_config):

if k in expanded_config:
raise ValueError("Bench name is not unique")

expanded_config[k] = v

return expanded_config
Expand Down
39 changes: 35 additions & 4 deletions milabench/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def text(self, x):
if not self.stdout:
return
if isinstance(x, DataFrame):
self._text(x.to_string(formatters=_formatters))
self._text(pandas_to_string(x, formatters=_formatters))
else:
self._text(str(x))

Expand Down Expand Up @@ -300,9 +300,39 @@ def _score(column):
out.finalize()


def pandas_to_string(df, formatters):
"""Default stdout printer does not insert a column sep which makes it hard to retranscribe results elsewhere.
to_csv does not align the output.
"""
from collections import defaultdict
columns = df.columns.tolist()

sep = " | "
lines = []
col_size = defaultdict(int)

for index, row in df.iterrows():
line = [f'{index:<30}']
for col, val in zip(columns, row):
fmt = formatters.get(col)
val = fmt(val)
col_size[col] = max(col_size[col], len(val))
line.append(val)

lines.append(sep.join(line))

def fmtcol(col):
size = col_size[col]
return f"{col:>{size}}"

header = sep.join([f"{'bench':<30}"] + [fmtcol(col) for col in columns])

return "\n".join([header] + lines)


_formatters = {
"fail": "{:4.0f}".format,
"n": "{:.0f}".format,
"fail": "{:.0f}".format,
"std": "{:10.2f}".format,
"iqr": "{:10.2f}".format,
"perf": "{:10.2f}".format,
Expand All @@ -314,8 +344,9 @@ def _score(column):
"std%": "{:6.1%}".format,
"sem%": "{:6.1%}".format,
"iqr%": "{:6.1%}".format,
"weight": "{:4.2f}".format,
"peak_memory": "{:.0f}".format,
"score": "{:10.2f}".format,
"weight": "{:5.2f}".format,
"peak_memory": "{:11.0f}".format,
0: "{:.0%}".format,
1: "{:.0%}".format,
2: "{:.0%}".format,
Expand Down

0 comments on commit d8c09b7

Please sign in to comment.