[TESTING] add diff column, option to return df in benchmark (#2469)

This commit is contained in:
Sam Shleifer
2023-10-23 22:17:00 -07:00
committed by GitHub
parent 8f467f1ea9
commit 12da43084b

View File

@@ -265,7 +265,7 @@ class Mark:
self.fn = fn
self.benchmarks = benchmarks
def _run(self, bench: Benchmark, save_path: str, show_plots: bool, print_data: bool, **kwrags):
def _run(self, bench: Benchmark, save_path: str, show_plots: bool, print_data: bool, diff_col=False, **kwrags):
import os
import matplotlib.pyplot as plt
@@ -321,24 +321,36 @@ class Mark:
if save_path:
plt.savefig(os.path.join(save_path, f"{bench.plot_name}.png"))
df = df[x_names + bench.line_names]
if diff_col and df.shape[1] == 2:
col0, col1 = df.columns.tolist()
df['Diff'] = df[col1] - df[col0]
if print_data:
print(bench.plot_name + ':')
print(df)
if save_path:
df.to_csv(os.path.join(save_path, f"{bench.plot_name}.csv"), float_format='%.1f', index=False)
return df
def run(self, show_plots=False, print_data=False, save_path='', **kwargs):
def run(self, show_plots=False, print_data=False, save_path='', return_df=False, **kwargs):
has_single_bench = isinstance(self.benchmarks, Benchmark)
benchmarks = [self.benchmarks] if has_single_bench else self.benchmarks
result_dfs = []
if save_path:
html = open(os.path.join(save_path, "results.html"), "w")
html.write("<html><body>\n")
for bench in benchmarks:
self._run(bench, save_path, show_plots, print_data, **kwargs)
result_dfs.append(self._run(bench, save_path, show_plots, print_data, **kwargs))
if save_path:
html.write(f"<image src=\"{bench.plot_name}.png\"/>\n")
if save_path:
html.write("</body></html>\n")
if return_df:
if has_single_bench:
return result_dfs[0]
else:
return result_dfs
return None
def perf_report(benchmarks):