Skip to content

Commit 7273f4a

Browse files
brunoborgesCopilot
andcommitted
fix: remove Windows from benchmark, fix measure() timing bugs
- Remove windows-latest from all 3 benchmark jobs (ubuntu-only) - Replace broken TIMEFORMAT/time subshell with portable python3 timing - Fix ((failures++)) returning exit code 1 under set -e - Fix measure() return 1 killing script under set -e - Update run.sh with same measure/avg_runs fixes - Update snippet count glob to include .yaml/.yml Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 9795287 commit 7273f4a

File tree

2 files changed

+50
-65
lines changed

2 files changed

+50
-65
lines changed

.github/workflows/benchmark.yml

Lines changed: 36 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ permissions:
99

1010
jobs:
1111
benchmark:
12-
strategy:
13-
matrix:
14-
os: [ubuntu-latest, windows-latest]
15-
runs-on: ${{ matrix.os }}
12+
runs-on: ubuntu-latest
1613
steps:
1714
- uses: actions/checkout@v6
1815

@@ -28,8 +25,7 @@ jobs:
2825
with:
2926
python-version: '3.13'
3027

31-
- name: Install system dependencies (Ubuntu)
32-
if: runner.os == 'Linux'
28+
- name: Install system dependencies
3329
run: sudo apt-get update && sudo apt-get install -y libcairo2-dev
3430

3531
- name: Install Python dependencies
@@ -46,41 +42,39 @@ jobs:
4642
4743
snippet_count=$(find content \( -name '*.json' -o -name '*.yaml' -o -name '*.yml' \) -not -name 'template.*' | wc -l | tr -d ' ')
4844
java_ver=$(java -version 2>&1 | head -1 | sed 's/.*"\(.*\)".*/\1/')
49-
os_name="${{ matrix.os }}"
45+
os_name="ubuntu-latest"
5046
51-
# Timing helper using bash TIMEFORMAT
47+
# Nanosecond timestamp helper
48+
_now() { python3 -c "import time; print(int(time.time()*1e9))"; }
49+
50+
# Timing helper — returns seconds or "FAIL"
5251
measure() {
53-
TIMEFORMAT='%R'
54-
local t ec
55-
t=$( { time "$@" > /dev/null 2>&1; ec=$?; } 2>&1 )
56-
if [[ ${ec:-1} -ne 0 ]]; then
57-
# Re-check: the subshell exit code isn't always captured
58-
if ! "$@" > /dev/null 2>&1; then
59-
echo "FAIL"
60-
return 1
61-
fi
52+
local start end
53+
start=$(_now)
54+
if "$@" > /dev/null 2>&1; then
55+
end=$(_now)
56+
awk "BEGIN {printf \"%.2f\", ($end - $start) / 1000000000}"
57+
else
58+
echo "FAIL"
6259
fi
63-
echo "$t"
6460
}
6561
6662
avg_runs() {
6763
local n="$1"; shift
68-
local sum=0 failures=0
64+
local sum=0 success=0
6965
for ((i = 1; i <= n; i++)); do
7066
local t
71-
t=$(measure "$@") || true
72-
if [[ "$t" == "FAIL" ]]; then
73-
((failures++)) || true
74-
continue
67+
t=$(measure "$@")
68+
if [[ "$t" != "FAIL" ]]; then
69+
sum=$(awk "BEGIN {print $sum + $t}")
70+
success=$((success + 1))
7571
fi
76-
sum=$(awk "BEGIN {print $sum + $t}")
7772
done
78-
local success=$((n - failures))
7973
if [[ $success -eq 0 ]]; then
8074
echo "FAIL"
81-
return 0
75+
else
76+
awk "BEGIN {printf \"%.2f\", $sum / $success}"
8277
fi
83-
awk "BEGIN {printf \"%.2f\", $sum / $success}"
8478
}
8579
8680
echo "Running benchmark on $os_name (Java $java_ver, $snippet_count snippets)..."
@@ -164,10 +158,7 @@ jobs:
164158
# Python and JBang start with zero caches, just like real CI.
165159
# ---------------------------------------------------------------------------
166160
build-jar:
167-
strategy:
168-
matrix:
169-
os: [ubuntu-latest, windows-latest]
170-
runs-on: ${{ matrix.os }}
161+
runs-on: ubuntu-latest
171162
steps:
172163
- uses: actions/checkout@v6
173164

@@ -188,7 +179,7 @@ jobs:
188179
- name: Upload JAR and AOT
189180
uses: actions/upload-artifact@v4
190181
with:
191-
name: generator-${{ matrix.os }}
182+
name: generator
192183
path: |
193184
html-generators/generate.jar
194185
html-generators/generate.aot
@@ -197,10 +188,7 @@ jobs:
197188
198189
ci-cold-start:
199190
needs: build-jar
200-
strategy:
201-
matrix:
202-
os: [ubuntu-latest, windows-latest]
203-
runs-on: ${{ matrix.os }}
191+
runs-on: ubuntu-latest
204192
steps:
205193
- uses: actions/checkout@v6
206194

@@ -214,8 +202,7 @@ jobs:
214202
with:
215203
python-version: '3.13'
216204

217-
- name: Install system dependencies (Ubuntu)
218-
if: runner.os == 'Linux'
205+
- name: Install system dependencies
219206
run: sudo apt-get update && sudo apt-get install -y libcairo2-dev
220207

221208
- name: Install Python dependencies
@@ -224,27 +211,27 @@ jobs:
224211
- name: Download JAR and AOT
225212
uses: actions/download-artifact@v4
226213
with:
227-
name: generator-${{ matrix.os }}
214+
name: generator
228215
path: html-generators
229216

230217
- name: CI cold-start benchmark
231218
shell: bash
232219
run: |
233-
os_name="${{ matrix.os }}"
220+
os_name="ubuntu-latest"
234221
java_ver=$(java -version 2>&1 | head -1 | sed 's/.*"\(.*\)".*/\1/')
235222
snippet_count=$(find content \( -name '*.json' -o -name '*.yaml' -o -name '*.yml' \) -not -name 'template.*' | wc -l | tr -d ' ')
236223
224+
_now() { python3 -c "import time; print(int(time.time()*1e9))"; }
225+
237226
measure() {
238-
TIMEFORMAT='%R'
239-
local t ec
240-
t=$( { time "$@" > /dev/null 2>&1; ec=$?; } 2>&1 )
241-
if [[ ${ec:-1} -ne 0 ]]; then
242-
if ! "$@" > /dev/null 2>&1; then
243-
echo "FAIL"
244-
return 1
245-
fi
227+
local start end
228+
start=$(_now)
229+
if "$@" > /dev/null 2>&1; then
230+
end=$(_now)
231+
awk "BEGIN {printf \"%.2f\", ($end - $start) / 1000000000}"
232+
else
233+
echo "FAIL"
246234
fi
247-
echo "$t"
248235
}
249236
250237
# Everything is cold: no __pycache__, no JBang cache, fresh JVM

html-generators/benchmark/run.sh

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,34 +31,32 @@ UPDATE_MD=false
3131
# Helpers
3232
# ---------------------------------------------------------------------------
3333
measure() {
34-
local t
35-
t=$( { /usr/bin/time -p "$@" > /dev/null; } 2>&1 | awk '/^real/ {print $2}' )
36-
# Verify the command actually succeeded
37-
if ! "$@" > /dev/null 2>&1; then
34+
local start end
35+
start=$(python3 -c "import time; print(time.time())")
36+
if "$@" > /dev/null 2>&1; then
37+
end=$(python3 -c "import time; print(time.time())")
38+
python3 -c "print(f'{$end - $start:.2f}')"
39+
else
3840
echo "FAIL"
39-
return 1
4041
fi
41-
echo "$t"
4242
}
4343

4444
avg_runs() {
4545
local n="$1"; shift
46-
local sum=0 failures=0
46+
local sum=0 success=0
4747
for ((i = 1; i <= n; i++)); do
4848
local t
49-
t=$(measure "$@") || true
50-
if [[ "$t" == "FAIL" ]]; then
51-
((failures++)) || true
52-
continue
49+
t=$(measure "$@")
50+
if [[ "$t" != "FAIL" ]]; then
51+
sum=$(echo "$sum + $t" | bc)
52+
success=$((success + 1))
5353
fi
54-
sum=$(echo "$sum + $t" | bc)
5554
done
56-
local success=$((n - failures))
5755
if [[ $success -eq 0 ]]; then
5856
echo "FAIL"
59-
return 0
57+
else
58+
echo "scale=2; $sum / $success" | bc | sed 's/^\./0./'
6059
fi
61-
echo "scale=2; $sum / $success" | bc | sed 's/^\./0./'
6260
}
6361

6462
# ---------------------------------------------------------------------------
@@ -70,7 +68,7 @@ JAVA_VER=$(java -version 2>&1 | head -1 | sed 's/.*"\(.*\)".*/\1/')
7068
JBANG_VER=$(jbang version 2>/dev/null || echo "n/a")
7169
PYTHON_VER=$(python3 --version 2>/dev/null | awk '{print $2}' || echo "n/a")
7270
OS=$(uname -s)
73-
SNIPPET_COUNT=$(find content -name '*.json' | wc -l | tr -d ' ')
71+
SNIPPET_COUNT=$(find content \( -name '*.json' -o -name '*.yaml' -o -name '*.yml' \) -not -name 'template.*' | wc -l | tr -d ' ')
7472

7573
echo ""
7674
echo "Environment: $CPU · $RAM · Java $JAVA_VER · $OS"

0 commit comments

Comments
 (0)