Skip to content

Commit 5635bf8

Browse files
committed
utility to fire execution of all benchmarking scripts.
1 parent 6815cae commit 5635bf8

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

benchmarks/run_all.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import glob
2+
import subprocess
3+
import pandas as pd
4+
import os
5+
6+
PATTERN = "benchmarking_*.py"
7+
FINAL_CSV_FILENAME = "collated_results.csv"
8+
GITHUB_SHA = os.getenv("GITHUB_SHA", None)
9+
10+
class SubprocessCallException(Exception):
11+
pass
12+
13+
14+
# Taken from `test_examples_utils.py`
15+
def run_command(command: list[str], return_stdout=False):
16+
"""
17+
Runs `command` with `subprocess.check_output` and will potentially return the `stdout`. Will also properly capture
18+
if an error occurred while running `command`
19+
"""
20+
try:
21+
output = subprocess.check_output(command, stderr=subprocess.STDOUT)
22+
if return_stdout:
23+
if hasattr(output, "decode"):
24+
output = output.decode("utf-8")
25+
return output
26+
except subprocess.CalledProcessError as e:
27+
raise SubprocessCallException(
28+
f"Command `{' '.join(command)}` failed with the following error:\n\n{e.output.decode()}"
29+
) from e
30+
31+
32+
def run_scripts():
33+
python_files = sorted(glob.glob(PATTERN))
34+
35+
for file in python_files:
36+
if file != "benchmarking_utils.py":
37+
print(f"****** Running file: {file} ******")
38+
command = f"python {file}"
39+
run_command(command.split())
40+
41+
42+
def merge_csvs():
43+
all_csvs = glob.glob("*.csv")
44+
final_df = pd.concat([pd.read_csv(f) for f in all_csvs]).reset_index(drop=True)
45+
if GITHUB_SHA:
46+
final_df["github_sha"] = GITHUB_SHA
47+
final_df.to_csv(FINAL_CSV_FILENAME)
48+
49+
50+
if __name__ == "__main__":
51+
run_scripts()
52+
merge_csvs()

0 commit comments

Comments
 (0)