Skip to content

Commit d4b5d03

Browse files
committed
Add benchmark charting script, output chart as part of release process
1 parent 721f3a5 commit d4b5d03

4 files changed

Lines changed: 202 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Static benchmark READMEs in `bench/` (small, medium, large, stress) exercise eve
134134
./bench/run --log # also save to bench/results.csv (should only be used by release script / only run when creating a new release)
135135
```
136136

137-
Benchmarks run automatically during `./release` and are recorded in `bench/results.csv`.
137+
Benchmarks run automatically during `./release` and are recorded in `bench/results.csv`. A chart (`bench/results.svg`) is also generated to visualize performance across releases (via `bench/chart`).
138138

139139
## Publishing a new release
140140

bench/chart

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#!/usr/bin/env bash
2+
# bench/chart — render bench/results.csv as an SVG line chart.
3+
#
4+
# Usage:
5+
# ./bench/chart # writes bench/results.svg
6+
7+
set -euo pipefail
8+
9+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
10+
CSV="$SCRIPT_DIR/results.csv"
11+
OUT="$SCRIPT_DIR/results.svg"
12+
13+
if [[ ! -f "$CSV" ]]; then
14+
echo "No results.csv found — run bench/run --log first" >&2
15+
exit 1
16+
fi
17+
18+
# ── Generate SVG via awk ─────────────────────────────────────────────────────
19+
20+
awk -F, '
21+
BEGIN {
22+
# Layout
23+
W = 1080; H = 840
24+
ML = 72; MR = 110; MT = 44; MB = 50 # margins
25+
PW = W - ML - MR; PH = H - MT - MB # plot area
26+
27+
# Fixture draw order and colours
28+
split("small,medium,large,stress", fix_order, ",")
29+
color["small"] = "#2563eb"
30+
color["medium"] = "#16a34a"
31+
color["large"] = "#ea580c"
32+
color["stress"] = "#dc2626"
33+
34+
nv = 0; max_ms = 0
35+
}
36+
37+
NR == 1 { next } # skip header
38+
39+
{
40+
v = $2; fixture = $4; ms = $6 + 0
41+
42+
# Track unique versions in order
43+
if (!(v in v_seen)) { v_seen[v] = 1; versions[nv++] = v }
44+
45+
data[fixture, v] = ms
46+
if (ms > max_ms) max_ms = ms
47+
}
48+
49+
END {
50+
# Linear scale: pick a clean step so we get ~8-12 grid lines
51+
ceil = max_ms * 1.1
52+
if (ceil <= 200) step = 20
53+
else if (ceil <= 500) step = 50
54+
else if (ceil <= 1200) step = 100
55+
else if (ceil <= 2500) step = 200
56+
else step = 500
57+
ceil = int((ceil + step - 1) / step) * step
58+
nsteps = int(ceil / step)
59+
60+
# ── SVG header ──────────────────────────────────────────────────────────
61+
print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
62+
printf "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"%d\" height=\"%d\" ", W, H
63+
printf "viewBox=\"0 0 %d %d\" font-family=\"system-ui,sans-serif\">\n", W, H
64+
65+
# Background
66+
printf "<rect width=\"%d\" height=\"%d\" fill=\"#fff\" rx=\"6\"/>\n", W, H
67+
68+
# Title
69+
printf "<text x=\"%d\" y=\"24\" font-size=\"15\" font-weight=\"600\" ", ML
70+
printf "fill=\"#1e293b\">hdi benchmark - median parse time</text>\n"
71+
72+
# ── Y axis grid + labels ────────────────────────────────────────────────
73+
for (i = 0; i <= nsteps; i++) {
74+
val = step * i
75+
y = MT + PH - (val / ceil) * PH
76+
printf "<line x1=\"%d\" y1=\"%.1f\" x2=\"%d\" y2=\"%.1f\" ", ML, y, ML + PW, y
77+
printf "stroke=\"#e2e8f0\" stroke-width=\"1\"/>\n"
78+
printf "<text x=\"%d\" y=\"%.1f\" text-anchor=\"end\" ", ML - 8, y + 4
79+
printf "font-size=\"11\" fill=\"#64748b\">%d</text>\n", val
80+
}
81+
82+
# Y axis title
83+
printf "<text x=\"14\" y=\"%d\" font-size=\"11\" fill=\"#64748b\" ", MT + PH/2
84+
printf "transform=\"rotate(-90,14,%d)\">ms</text>\n", MT + PH/2
85+
86+
# ── X axis labels ───────────────────────────────────────────────────────
87+
for (i = 0; i < nv; i++) {
88+
x = ML + (nv > 1 ? (i / (nv - 1)) * PW : PW / 2)
89+
y = MT + PH + 20
90+
printf "<text x=\"%.1f\" y=\"%d\" text-anchor=\"middle\" ", x, y
91+
printf "font-size=\"11\" fill=\"#64748b\">%s</text>\n", versions[i]
92+
}
93+
94+
# X axis title
95+
printf "<text x=\"%d\" y=\"%d\" text-anchor=\"middle\" ", ML + PW/2, MT + PH + 40
96+
printf "font-size=\"11\" fill=\"#64748b\">release</text>\n"
97+
98+
# ── Data lines ──────────────────────────────────────────────────────────
99+
for (f = 1; f <= 4; f++) {
100+
fix = fix_order[f]
101+
c = color[fix]
102+
103+
# Polyline path
104+
printf "<polyline fill=\"none\" stroke=\"%s\" stroke-width=\"2\" ", c
105+
printf "stroke-linejoin=\"round\" points=\""
106+
for (i = 0; i < nv; i++) {
107+
ms = data[fix, versions[i]] + 0
108+
x = ML + (nv > 1 ? (i / (nv - 1)) * PW : PW / 2)
109+
y = MT + PH - (ms / ceil) * PH
110+
if (i > 0) printf " "
111+
printf "%.1f,%.1f", x, y
112+
}
113+
printf "\"/>\n"
114+
115+
# Dots
116+
for (i = 0; i < nv; i++) {
117+
ms = data[fix, versions[i]] + 0
118+
if (ms == 0) continue
119+
x = ML + (nv > 1 ? (i / (nv - 1)) * PW : PW / 2)
120+
y = MT + PH - (ms / ceil) * PH
121+
printf "<circle cx=\"%.1f\" cy=\"%.1f\" r=\"3.5\" ", x, y
122+
printf "fill=\"%s\" stroke=\"#fff\" stroke-width=\"1.5\"/>\n", c
123+
}
124+
}
125+
126+
# ── Legend ───────────────────────────────────────────────────────────────
127+
lx = ML + PW + 16
128+
for (f = 1; f <= 4; f++) {
129+
fix = fix_order[f]
130+
ly = MT + 4 + (f - 1) * 22
131+
printf "<circle cx=\"%d\" cy=\"%d\" r=\"5\" fill=\"%s\"/>\n", lx, ly, color[fix]
132+
printf "<text x=\"%d\" y=\"%d\" font-size=\"12\" fill=\"#334155\">%s</text>\n", lx + 12, ly + 4, fix
133+
}
134+
135+
print "</svg>"
136+
}
137+
' "$CSV" > "$OUT"
138+
139+
printf " Chart saved to bench/results.svg\n"

bench/results.svg

Lines changed: 60 additions & 0 deletions
Loading

release

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ sed -i.bak "s/^VERSION=\"$current\"/VERSION=\"$new\"/" "$HDI" && rm -f "$HDI.bak
6767
if [[ -x "$SCRIPT_DIR/bench/run" ]]; then
6868
echo ""
6969
"$SCRIPT_DIR/bench/run" --log
70+
"$SCRIPT_DIR/bench/chart"
7071
fi
7172

72-
git add hdi bench/results.csv
73+
git add hdi bench/results.csv bench/results.svg
7374
git commit -m "Bump version to $new"
7475
git tag "$tag"
7576
git push origin HEAD --tags

0 commit comments

Comments
 (0)