Skip to content

Commit

Permalink
Generate plots of performance results
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelmior authored Aug 28, 2024
1 parent c34b4dc commit fbaa073
Show file tree
Hide file tree
Showing 8 changed files with 378 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ indent_style = tab

[*.uk]
indent_style = tab

[*.py]
indent_size = 4
12 changes: 12 additions & 0 deletions .github/plot_markdown.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import glob
import json
import os


if __name__ == '__main__':
img_urls = json.loads(os.environ['IMG_URLS'])
img_files = glob.glob('dist/results/plots/*.png')
for (url, file) in zip(img_urls, img_files):
name = file.split('/')[-1].split('.')[0]
print(f"## {name}")
print(f"![{name}]({url})\n")
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install uv
run: |
pipx install uv
touch README.md
mkdir -p src/jsonschema_benchmark
touch src/jsonschema_benchmark/__init__.py
- run: make
- run: cat dist/report.csv
- name: Read CSV
Expand All @@ -29,3 +36,14 @@ jobs:
MARKDOWN_TABLE: ${{ steps.csv-table-output.outputs.markdown-table }}
run: echo "$MARKDOWN_TABLE" >> $GITHUB_STEP_SUMMARY

- run: make plots
- name: Upload plots
id: imgur
uses: devicons/[email protected]
with:
path: dist/results/plots/*.png
client_id: ${{secrets.IMGUR_CLIENT_ID}}
- name: Add plots to summary
env:
IMG_URLS: ${{ steps.imgur.outputs.imgur_urls }}
run: python .github/plot_markdown.py >> $GITHUB_STEP_SUMMARY
2 changes: 2 additions & 0 deletions .venv/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,24 @@ node_modules: package.json package-lock.json ; npm ci
clean: ; rm -rf dist node_modules
dist: ; mkdir $@
dist/results: | dist ; mkdir $@
dist/results/plots: | dist/results ; mkdir $@
dist/temp: | dist ; mkdir $@
define PREPARE_IMPLEMENTATION
dist/results/$1: | dist/results ; mkdir $$@
dist/temp/$1: | dist/temp ; mkdir $$@
ALL_TARGETS += $$(addprefix dist/results/$1/,$(SCHEMAS))
endef
ALL_PLOTS := $(foreach schema,$(SCHEMAS),dist/results/plots/$(schema).png)
$(foreach implementation,$(IMPLEMENTATIONS),$(eval $(call PREPARE_IMPLEMENTATION,$(implementation))))
dist/report.csv: report.sh $(ALL_TARGETS) | dist ; ./$< $(ALL_TARGETS) > $@
dist/results/plots/%.png: \
dist/results/plots \
dist/report.csv \
plot.py \
schemas/%/schema.json \
schemas/%/instances.jsonl
uv run python plot.py
plots: $(ALL_PLOTS)
.PHONY: all
all: dist/report.csv ; cat $<

Expand Down
25 changes: 25 additions & 0 deletions plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from collections import defaultdict
import csv

import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns



if __name__ == "__main__":
examples = defaultdict(list)
with open("dist/report.csv") as f:
reader = csv.DictReader(f)
for row in reader:
row['milliseconds'] = float(row['nanoseconds']) / 1e6
examples[row["name"]].append(row)

for (name, data) in examples.items():
data = pd.DataFrame(data)
plt.figure(figsize=(4, 3), dpi=96)
plot = sns.barplot(data, x="implementation", y="milliseconds", errorbar=None)
plot.set(xlabel=None)
plot.get_figure().savefig(f"dist/results/plots/{name}.png", dpi=96)
plt.clf()

13 changes: 13 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[project]
name = "jsonschema-benchmark"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"seaborn>=0.13.2",
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
295 changes: 295 additions & 0 deletions uv.lock

Large diffs are not rendered by default.

0 comments on commit fbaa073

Please sign in to comment.