Skip to content

Commit 798f055

Browse files
Copilotmrjf
andauthored
perf-comparison: run benchmarks during evaluation so results.json holds real data
Agent-Logs-Url: https://github.com/githubnext/tsessebe/sessions/cb4498ea-d02b-4dba-91a5-1be05efb5fe7 Co-authored-by: mrjf <180956+mrjf@users.noreply.github.com>
1 parent 1415e7b commit 798f055

1 file changed

Lines changed: 51 additions & 16 deletions

File tree

.autoloop/programs/perf-comparison/program.md

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ This is an open-ended program — it runs continuously, always adding the next b
2222
- Creates the same dataset as the TypeScript version
2323
- Runs the same operation with the same loop structure
2424
- Outputs the same JSON format
25-
5. **Run both benchmarks** via `benchmarks/run_benchmarks.sh` and capture results.
26-
6. **Update `benchmarks/results.json`** with the new timing data.
27-
7. **Update `playground/benchmarks.html`** to display the new function's comparison metrics.
25+
5. **Update `playground/benchmarks.html`** if needed to display the new function's comparison metrics.
26+
27+
The evaluation step (below) runs `benchmarks/run_benchmarks.sh` to execute **every** TS/Python benchmark pair and regenerates `benchmarks/results.json` with the real timing data. That regenerated file is what gets committed on a successful iteration, so when the autoloop branch is merged to `main`, the pages workflow (`.github/workflows/pages.yml`) picks up the real results and `playground/benchmarks.html` renders real comparison data instead of "No benchmark data available yet."
2828

2929
### Key constraints
3030

@@ -50,24 +50,59 @@ Do NOT modify:
5050

5151
## Evaluation
5252

53+
The evaluation runs `benchmarks/run_benchmarks.sh`, which executes every TS/Python
54+
benchmark pair and writes real timing data to `benchmarks/results.json`. The metric
55+
is the number of benchmarks that appear in that regenerated file — i.e. the number
56+
of function pairs whose benchmarks actually ran to completion and produced valid
57+
JSON output. This means a benchmark pair is only "counted" if it truly runs, and
58+
the committed `benchmarks/results.json` always reflects real data that the
59+
`pages.yml` workflow will copy to the playground on merge to `main`.
60+
5361
```bash
54-
# Set up Python environment if needed
62+
set -euo pipefail
63+
64+
# Ensure Python and pandas are available
5565
if ! command -v python3 &>/dev/null; then
56-
echo "Python3 not found, skipping"
66+
echo "ERROR: python3 is required but not found" >&2
67+
exit 1
5768
fi
58-
pip3 install pandas --quiet 2>/dev/null || true
59-
60-
# Count the number of benchmark pairs (functions with both TS and Python benchmarks)
61-
ts_benchmarks=$(ls benchmarks/tsb/bench_*.ts 2>/dev/null | wc -l | tr -d ' ')
62-
py_benchmarks=$(ls benchmarks/pandas/bench_*.py 2>/dev/null | wc -l | tr -d ' ')
63-
64-
# The metric is the minimum of the two (both must exist for a complete benchmark)
65-
if [ "$ts_benchmarks" -lt "$py_benchmarks" ]; then
66-
count=$ts_benchmarks
67-
else
68-
count=$py_benchmarks
69+
python3 -c "import pandas" 2>/dev/null || pip3 install pandas --quiet
70+
71+
# Ensure Bun is available (install if missing — autoloop runners may not have it).
72+
# Failure to install Bun is logged but does not abort the script, because we must
73+
# still emit the final metric line for autoloop to parse.
74+
if ! command -v bun &>/dev/null; then
75+
curl -fsSL https://bun.sh/install | bash || echo "WARN: bun install script failed" >&2
76+
export PATH="$HOME/.bun/bin:$PATH"
77+
fi
78+
if ! command -v bun &>/dev/null; then
79+
echo "ERROR: bun is not available after install attempt; benchmarks will fail" >&2
6980
fi
7081

82+
# Install JS/TS dependencies so benchmark scripts can import from src/.
83+
# `|| true` keeps the script alive so the final metric is still emitted; any
84+
# errors are visible in the autoloop logs for debugging.
85+
bun install --silent || echo "WARN: bun install failed; benchmarks may fail to import src/" >&2
86+
87+
# Run every benchmark pair and regenerate benchmarks/results.json with real data.
88+
# This is the file .github/workflows/pages.yml copies into the playground, so
89+
# committing it here is what makes real benchmark data appear on the pages site
90+
# once the autoloop branch is merged to main. Output is left visible so
91+
# per-benchmark failures can be diagnosed from autoloop logs; `|| true` ensures
92+
# we still reach the metric emission below if the script exits nonzero.
93+
bash benchmarks/run_benchmarks.sh || echo "WARN: run_benchmarks.sh exited nonzero" >&2
94+
95+
# Metric: number of benchmark entries in the regenerated results.json.
96+
count=$(python3 -c "
97+
import json
98+
try:
99+
with open('benchmarks/results.json') as f:
100+
data = json.load(f)
101+
print(len(data.get('benchmarks', [])))
102+
except Exception:
103+
print(0)
104+
")
105+
71106
echo "{\"benchmarked_functions\": ${count:-0}}"
72107
```
73108

0 commit comments

Comments
 (0)