Skip to content

Commit 5b9a1ed

Browse files
brunoborgesCopilot
andcommitted
Add cross-platform benchmark workflow (manual trigger)
Benchmarks Fat JAR+AOT, Fat JAR, JBang, and Python across ubuntu, windows, and macos. Results written to job summary. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 9d3a9ad commit 5b9a1ed

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

.github/workflows/benchmark.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Benchmark Generator
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
contents: read
8+
actions: write
9+
10+
jobs:
11+
benchmark:
12+
strategy:
13+
matrix:
14+
os: [ubuntu-latest, windows-latest, macos-latest]
15+
runs-on: ${{ matrix.os }}
16+
steps:
17+
- uses: actions/checkout@v6
18+
19+
- uses: actions/setup-java@v5
20+
with:
21+
distribution: 'temurin'
22+
java-version: '25'
23+
24+
- uses: jbangdev/setup-jbang@main
25+
26+
- name: Setup Python
27+
uses: actions/setup-python@v5
28+
with:
29+
python-version: '3.13'
30+
31+
- name: Build fat JAR
32+
run: jbang export fatjar --force --output html-generators/generate.jar html-generators/generate.java
33+
34+
- name: Build AOT cache
35+
run: java -XX:AOTCacheOutput=html-generators/generate.aot -jar html-generators/generate.jar
36+
37+
- name: Run benchmark
38+
shell: bash
39+
run: |
40+
JAR="html-generators/generate.jar"
41+
AOT="html-generators/generate.aot"
42+
RUNS=6
43+
44+
snippet_count=$(find content -name '*.json' | wc -l | tr -d ' ')
45+
java_ver=$(java -version 2>&1 | head -1 | sed 's/.*"\(.*\)".*/\1/')
46+
os_name="${{ matrix.os }}"
47+
48+
# Timing helper using bash TIMEFORMAT
49+
measure() {
50+
TIMEFORMAT='%R'
51+
local t
52+
t=$( { time "$@" > /dev/null 2>&1; } 2>&1 )
53+
echo "$t"
54+
}
55+
56+
bench() {
57+
local label="$1"; shift
58+
local times=()
59+
for ((i = 1; i <= RUNS; i++)); do
60+
t=$(measure "$@")
61+
times+=("$t")
62+
done
63+
local cold="${times[0]}"
64+
local sum=0
65+
for ((i = 1; i < RUNS; i++)); do
66+
sum=$(awk "BEGIN {print $sum + ${times[$i]}}")
67+
done
68+
local warm
69+
warm=$(awk "BEGIN {printf \"%.2f\", $sum / ($RUNS - 1)}")
70+
echo "${label}|${cold}|${warm}"
71+
}
72+
73+
echo "Running benchmark on $os_name (Java $java_ver, $snippet_count snippets)..."
74+
75+
aot_result=$(bench "Fat JAR + AOT" java -XX:AOTCache="$AOT" -jar "$JAR")
76+
jar_result=$(bench "Fat JAR" java -jar "$JAR")
77+
jbang_result=$(bench "JBang" jbang html-generators/generate.java)
78+
python_result=$(bench "Python" python3 html-generators/generate.py)
79+
80+
# Write to GitHub Actions Job Summary
81+
{
82+
echo "## Benchmark Results — \`$os_name\`"
83+
echo ""
84+
echo "Java $java_ver · $snippet_count snippets · $RUNS runs (1 cold + $((RUNS - 1)) warm)"
85+
echo ""
86+
echo "| Method | Cold Start | Warm Average |"
87+
echo "|--------|-----------|-------------|"
88+
for result in "$aot_result" "$jar_result" "$jbang_result" "$python_result"; do
89+
IFS='|' read -r label cold warm <<< "$result"
90+
echo "| **$label** | ${cold}s | ${warm}s |"
91+
done
92+
} >> "$GITHUB_STEP_SUMMARY"

0 commit comments

Comments
 (0)