Skip to content

Commit

Permalink
Compress benchmark results
Browse files Browse the repository at this point in the history
  • Loading branch information
shBLOCK committed May 11, 2024
1 parent a8a8ae6 commit 09f922d
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 402,628 deletions.
11 changes: 6 additions & 5 deletions benchmark/benchmarking.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import gzip
import inspect
import json
import math
Expand Down Expand Up @@ -533,14 +534,14 @@ def clear_env():
Subject.instances.clear()

def save_result(result: BenchmarkResult, file: Path):
"""Save the result and the current environment to a json file."""
"""Save the result and the current environment to a gzipped json file."""
log(f"Saving to {file}...")
with file.open("w", encoding="utf8") as f:
json.dump(serialize(result), f, indent=4, ensure_ascii=False)
with gzip.open(file, "wt", encoding="utf8") as f:
json.dump(serialize(result), f, ensure_ascii=False)

def load_result(file: Path) -> BenchmarkResult:
"""Restore the result and the environment from a json file."""
"""Restore the result and the environment from a gzipped json file."""
log(f"Loading from {file}...")
with file.open("r", encoding="utf8") as f:
with gzip.open(file, "rt", encoding="utf8") as f:
result = deserialize(json.load(f))
return result
2 changes: 1 addition & 1 deletion benchmark/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,4 @@ def _():
order_permutations=True,
min_runs_per_case=100
)
save_result(result, Path("results", result.datetime.strftime("%Y%m%d_%H-%M-%S") + ".json"))
save_result(result, Path("results", result.datetime.strftime("%Y%m%d_%H-%M-%S") + ".dat"))
35 changes: 16 additions & 19 deletions benchmark/gen_charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,29 @@
from benchmarking import load_result, clear_env, Path, Subject, log, indent_log


files = [f[:-5] for f in os.listdir("results") if f.endswith(".json")]
files = [f[:-4] for f in os.listdir("results") if f.endswith(".dat")]
# Latest to earliest
files.sort(reverse=True, key=lambda f: datetime.datetime.strptime(f, "%Y%m%d_%H-%M-%S"))

for file in files:
log(f"{file}:")
with indent_log():
try:
result = load_result(Path(f"results/{file}.json"))
log("Generating chart...")
chart = charting.chart(
result,
Subject.get_instance("pure_python"),
fig_height=5,
subtitles=(
f"{result.datetime.strftime("%Y/%d/%m-%H:%M")} · "
f"{result.metadata.py_impl} {result.metadata.py_ver} · "
f"{result.metadata.system} · "
f"{result.metadata.cpu}"
+ (" (GitHub Actions)" if result.metadata.ci else "")
,
)
result = load_result(Path(f"results/{file}.dat"))
log("Generating chart...")
chart = charting.chart(
result,
Subject.get_instance("pure_python"),
fig_height=5,
subtitles=(
f"{result.datetime.strftime("%Y/%d/%m-%H:%M")} · "
f"{result.metadata.py_impl} {result.metadata.py_ver} · "
f"{result.metadata.system} · "
f"{result.metadata.cpu}"
+ (" (GitHub Actions)" if result.metadata.ci else "")
,
)
chart.savefig(f"charts/{file}.svg")
except Exception as e:
log(f"Failed to generate chart for {file}.json: {repr(e)}")
)
chart.savefig(f"charts/{file}.svg")
clear_env()

log()
Expand Down
Binary file added benchmark/results/20240511_04-32-44.dat
Binary file not shown.
Loading

0 comments on commit 09f922d

Please sign in to comment.