Skip to content

Commit 0a97c77

Browse files
committed
Write machine specs to benchmark logs, default to not write to log
1 parent 96e3d47 commit 0a97c77

4 files changed

Lines changed: 50 additions & 30 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ This outputs `demo.gif` from the tape file.
130130
Static benchmark READMEs in `bench/` (small, medium, large, stress) exercise every parsing path at different scales. Run benchmarks with:
131131

132132
```bash
133-
./bench/run # run and append to bench/results.md
134-
./bench/run --no-log # print results only, don't log
133+
./bench/run # run benchmarks, print results
134+
./bench/run --log # also save to bench/results.csv (should only be used by release script / run when creating a new release)
135135
```
136136

137137
Benchmarks run automatically during `./release` and are recorded in `bench/results.csv`.

bench/results.csv

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
timestamp,version,fixture,lines,median_ms
2-
2026-03-17T22:32:43Z,0.7.0,small,21,98.8
3-
2026-03-17T22:32:43Z,0.7.0,medium,164,466.8
4-
2026-03-17T22:32:43Z,0.7.0,large,439,915.3
5-
2026-03-17T22:32:43Z,0.7.0,stress,561,1084.2
6-
2026-03-17T22:37:47Z,0.8.0,small,21,100.3
7-
2026-03-17T22:37:47Z,0.8.0,medium,164,474.8
8-
2026-03-17T22:37:47Z,0.8.0,large,439,989.7
9-
2026-03-17T22:37:47Z,0.8.0,stress,561,1064.1
10-
2026-03-17T22:39:13Z,0.9.0,small,21,99.8
11-
2026-03-17T22:39:13Z,0.9.0,medium,164,472.3
12-
2026-03-17T22:39:13Z,0.9.0,large,439,925.7
13-
2026-03-17T22:39:13Z,0.9.0,stress,561,1058.8
1+
timestamp,version,machine,fixture,lines,median_ms
2+
2026-03-17T22:32:43Z,0.7.0,Apple_M1_Pro_8c,small,21,98.8
3+
2026-03-17T22:32:43Z,0.7.0,Apple_M1_Pro_8c,medium,164,466.8
4+
2026-03-17T22:32:43Z,0.7.0,Apple_M1_Pro_8c,large,439,915.3
5+
2026-03-17T22:32:43Z,0.7.0,Apple_M1_Pro_8c,stress,561,1084.2
6+
2026-03-17T22:37:47Z,0.8.0,Apple_M1_Pro_8c,small,21,100.3
7+
2026-03-17T22:37:47Z,0.8.0,Apple_M1_Pro_8c,medium,164,474.8
8+
2026-03-17T22:37:47Z,0.8.0,Apple_M1_Pro_8c,large,439,989.7
9+
2026-03-17T22:37:47Z,0.8.0,Apple_M1_Pro_8c,stress,561,1064.1
10+
2026-03-17T22:53:19Z,0.9.0,Apple_M1_Pro_8c,small,21,102.8
11+
2026-03-17T22:53:19Z,0.9.0,Apple_M1_Pro_8c,medium,164,502.4
12+
2026-03-17T22:53:19Z,0.9.0,Apple_M1_Pro_8c,large,439,973.9
13+
2026-03-17T22:53:19Z,0.9.0,Apple_M1_Pro_8c,stress,561,1100.5

bench/run

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# bench/run — benchmark hdi against static READMEs and report timings.
33
#
44
# Usage:
5-
# ./bench/run # run benchmarks, print results, append to log
6-
# ./bench/run --no-log # run benchmarks, print results only
5+
# ./bench/run # run benchmarks, print results only
6+
# ./bench/run --log # also save to bench/results.csv (used by release)
77

88
set -euo pipefail
99

@@ -19,19 +19,39 @@ median() {
1919
sort -n | awk '{a[NR]=$1} END {print a[int((NR+1)/2)]}'
2020
}
2121

22-
time_ms() {
23-
local start end
24-
start=$(/usr/bin/perl -MTime::HiRes=time -e 'printf "%.6f\n", time')
25-
"$@" >/dev/null 2>&1
26-
end=$(/usr/bin/perl -MTime::HiRes=time -e 'printf "%.6f\n", time')
27-
/usr/bin/perl -e "printf \"%.1f\n\", ($end - $start) * 1000"
28-
}
22+
if [[ "$(uname)" == "Darwin" ]]; then
23+
time_ms() {
24+
local start end
25+
start=$(/usr/bin/perl -MTime::HiRes=time -e 'printf "%.6f\n", time')
26+
"$@" >/dev/null 2>&1
27+
end=$(/usr/bin/perl -MTime::HiRes=time -e 'printf "%.6f\n", time')
28+
/usr/bin/perl -e "printf \"%.1f\n\", ($end - $start) * 1000"
29+
}
30+
else
31+
time_ms() {
32+
local start end
33+
start=$(date +%s%N)
34+
"$@" >/dev/null 2>&1
35+
end=$(date +%s%N)
36+
echo "$(( (end - start) / 1000000 )).$(( (end - start) / 100000 % 10 ))"
37+
}
38+
fi
2939

30-
# ── Version info ─────────────────────────────────────────────────────────────
40+
# ── Version and machine info ──────────────────────────────────────────────────
3141

3242
version=$(grep -m1 '^VERSION=' "$HDI" | sed 's/VERSION="//;s/"//')
3343
timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
3444

45+
# Build a short machine identifier: Brand_Model_Cores
46+
if [[ "$(uname)" == "Darwin" ]]; then
47+
chip=$(sysctl -n machdep.cpu.brand_string 2>/dev/null | sed 's/ /_/g')
48+
cores=$(sysctl -n hw.ncpu 2>/dev/null)
49+
else
50+
chip=$(grep -m1 'model name' /proc/cpuinfo 2>/dev/null | sed 's/.*: //;s/ /_/g')
51+
cores=$(nproc 2>/dev/null)
52+
fi
53+
machine="${chip:-unknown}_${cores:-?}c"
54+
3555
# ── Benchmark ────────────────────────────────────────────────────────────────
3656

3757
declare -a names=()
@@ -62,7 +82,7 @@ done
6282
# ── Print results ────────────────────────────────────────────────────────────
6383

6484
printf "\n"
65-
printf " hdi %s\n" "$version"
85+
printf " hdi %s on %s\n" "$version" "$machine"
6686
printf " %s — %d runs per fixture\n\n" "$timestamp" "$RUNS"
6787
printf " %-12s %6s %8s\n" "Fixture" "Lines" "Median"
6888
printf " %-12s %6s %8s\n" "───────" "─────" "──────"
@@ -73,12 +93,12 @@ printf "\n"
7393

7494
# ── Log to CSV ───────────────────────────────────────────────────────────────
7595

76-
if [[ "${1:-}" == "--no-log" ]]; then
96+
if [[ "${1:-}" != "--log" ]]; then
7797
exit 0
7898
fi
7999

80100
if [[ ! -f "$LOG" ]]; then
81-
echo "timestamp,version,fixture,lines,median_ms" > "$LOG"
101+
echo "timestamp,version,machine,fixture,lines,median_ms" > "$LOG"
82102
fi
83103

84104
# Remove any existing rows for this version (keep header + other versions)
@@ -88,7 +108,7 @@ mv "$tmpfile" "$LOG"
88108

89109
# Append new rows
90110
for i in "${!names[@]}"; do
91-
echo "$timestamp,$version,${names[$i]},${lines[$i]},${medians[$i]}" >> "$LOG"
111+
echo "$timestamp,$version,$machine,${names[$i]},${lines[$i]},${medians[$i]}" >> "$LOG"
92112
done
93113

94114
printf " Logged to bench/results.csv\n\n"

release

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ sed -i.bak "s/^VERSION=\"$current\"/VERSION=\"$new\"/" "$HDI" && rm -f "$HDI.bak
6666
# Run benchmarks against the new version
6767
if [[ -x "$SCRIPT_DIR/bench/run" ]]; then
6868
echo ""
69-
"$SCRIPT_DIR/bench/run"
69+
"$SCRIPT_DIR/bench/run" --log
7070
fi
7171

7272
git add hdi bench/results.csv

0 commit comments

Comments
 (0)