Skip to content

Commit a42f0a4

Browse files
LDeng0205petervdonovan
authored andcommitted
modified runner script for continuous benchmarking
1 parent 996f239 commit a42f0a4

File tree

2 files changed

+50
-22
lines changed

2 files changed

+50
-22
lines changed

runner/conf/default.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ lf_path: "${oc.env:LF_PATH}"
66
bench_path: "${oc.env:LF_BENCHMARKS_PATH}"
77
continue_on_error: False
88
test_mode: False
9+
json: False
910
defaults:
1011
- benchmark: ???
1112
- target: ???

runner/run_benchmark.py

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import multiprocessing
77
import omegaconf
88
import subprocess
9-
9+
import json
1010

1111
log = logging.getLogger("run_benchmark")
1212

@@ -166,28 +166,55 @@ def execute_command(command):
166166

167167

168168
def write_results(times, cfg):
169-
row = {
170-
"benchmark": cfg["benchmark"]["name"],
171-
"target": cfg["target"]["name"],
172-
"total_iterations": cfg["iterations"],
173-
"threads": cfg["threads"],
174-
"iteration": None,
175-
"time_ms": None,
176-
}
177-
# also add all parameters and their values
178-
row.update(cfg["benchmark"]["params"])
179-
if "params" in cfg["target"]:
180-
row.update(cfg["target"]["params"])
181-
182-
with open("results.csv", "w", newline="") as csvfile:
183-
writer = csv.DictWriter(csvfile, fieldnames=row.keys())
184-
writer.writeheader()
185-
i = 0
169+
if not cfg["json"]:
170+
row = {
171+
"benchmark": cfg["benchmark"]["name"],
172+
"target": cfg["target"]["name"],
173+
"total_iterations": cfg["iterations"],
174+
"threads": cfg["threads"],
175+
"iteration": None,
176+
"time_ms": None,
177+
}
178+
# also add all parameters and their values
179+
row.update(cfg["benchmark"]["params"])
180+
if "params" in cfg["target"]:
181+
row.update(cfg["target"]["params"])
182+
183+
with open("results.csv", "w", newline="") as csvfile:
184+
writer = csv.DictWriter(csvfile, fieldnames=row.keys())
185+
writer.writeheader()
186+
i = 0
187+
for t in times:
188+
row["iteration"] = i
189+
row["time_ms"] = t
190+
writer.writerow(row)
191+
i += 1
192+
else:
193+
total_time = 0
186194
for t in times:
187-
row["iteration"] = i
188-
row["time_ms"] = t
189-
writer.writerow(row)
190-
i += 1
195+
total_time += t
196+
total_time /= cfg["iterations"]
197+
data = {
198+
"name": cfg["benchmark"]["name"],
199+
"unit": "ms",
200+
"value": total_time,
201+
"extra": f"Target: {cfg['target']['name']}\nTotal Iterations: {cfg['iterations']}\nThreads: {cfg['threads']}"
202+
}
203+
204+
try:
205+
with open("../../../benchmark_result.json", "r+") as outfile:
206+
# benchmark_result.json file should be in the multirun directory
207+
# update existing file
208+
contents = json.load(outfile)
209+
contents.append(data)
210+
outfile.seek(0)
211+
json.dump(contents, outfile, indent=4)
212+
213+
except FileNotFoundError:
214+
with open("../../../benchmark_result.json", "w+") as outfile:
215+
# create new file
216+
json.dump([data], outfile, indent=4)
217+
191218

192219

193220
if __name__ == "__main__":

0 commit comments

Comments
 (0)