@@ -10,6 +10,7 @@ OUT_DIR=$(dirname "$COMMENT")
1010META_WORKSPACE=" ${TARGET_WORKSPACE} -meta"
1111
1212failed=false
13+ section_open=false
1314
1415mkdir -p " $OUT_DIR "
1516OUT_MD=" $OUT_DIR /out.md"
@@ -31,10 +32,23 @@ write_section() {
3132 local title=" $1 "
3233 local description=" ${2:- } "
3334
35+ close_section
36+ write_blank_line
37+ write_line " <details>"
38+ write_line " <summary>$title </summary>"
3439 write_blank_line
35- write_line " ## $title "
3640 if [ -n " $description " ]; then
3741 write_line " $description "
42+ write_blank_line
43+ fi
44+ section_open=true
45+ }
46+
47+ close_section () {
48+ if [ " $section_open " = true ]; then
49+ write_blank_line
50+ write_line " </details>"
51+ section_open=false
3852 fi
3953}
4054
@@ -66,24 +80,20 @@ check_variance() {
6680 fi
6781}
6882
69- write_benchmark_details () {
70- write_line " <details>"
71- write_line " <summary>Benchmark details</summary>"
72- write_blank_line
73- cat " $OUT_MD " >> " $COMMENT "
74- write_blank_line
75- write_line " </details>"
76- }
77-
7883benchmark () {
79- local label=" $1 "
80- local cmd=" $2 "
81- local warmup=" ${3:- 3} "
82- local runs=" ${4:- 30} "
83- local setup=" ${5:- } "
84- local prepare=" ${6:- } "
85- local check_change=" ${7:- false} "
86- local -a hyperfine_args=(-i -N -w " $warmup " -r " $runs " --export-markdown " $OUT_MD " --export-json " $OUT_JSON " --show-output)
84+ local cmd=" $1 "
85+ local warmup=" ${2:- 3} "
86+ local runs=" ${3:- 30} "
87+ local setup=" ${4:- } "
88+ local prepare=" ${5:- } "
89+ local check_change=" ${6:- false} "
90+ local label_suffix=" ${7:- } "
91+ local label=" prek $cmd "
92+ local -a hyperfine_args=(-i -N -w " $warmup " -r " $runs " --export-markdown " $OUT_MD " --export-json " $OUT_JSON " )
93+
94+ if [ -n " $label_suffix " ]; then
95+ label=" $label $label_suffix "
96+ fi
8797
8898 if [ -n " $setup " ]; then
8999 hyperfine_args+=(--setup " $setup " )
@@ -93,12 +103,14 @@ benchmark() {
93103 hyperfine_args+=(--prepare " $prepare " )
94104 fi
95105
106+ write_blank_line
96107 write_line " ### \` $label \` "
97108 if ! hyperfine " ${hyperfine_args[@]} " --reference " $BASE_BINARY $cmd " " $HEAD_BINARY $cmd " ; then
98109 write_line " ⚠️ Benchmark failed for: $cmd "
99110 return 1
100111 fi
101- write_benchmark_details
112+ cat " $OUT_MD " >> " $COMMENT "
113+ write_blank_line
102114 if [ " $check_change " = " true" ]; then
103115 check_variance " $cmd "
104116 fi
@@ -129,20 +141,26 @@ EOF
129141
130142 git add -A
131143 git commit -m " Meta hooks test" || { echo " Failed to commit meta hooks test" ; exit 1; }
132- prek install-hooks
144+ $HEAD_BINARY install-hooks
133145}
134146
135147# Add environment metadata
136- write_line " ## Hyperfine Performance"
148+ write_line " ## ⚡️ Hyperfine Performance"
149+ write_blank_line
150+ write_line " <details>"
151+ write_line " <summary>Environment</summary>"
137152write_blank_line
138- write_line " **Environment:**"
139153write_line " - OS: $( uname -s) $( uname -r) "
140154write_line " - CPU: $( nproc) cores"
141155write_line " - prek version: $CURRENT_PREK_VERSION "
142156write_line " - Rust version: $( rustc --version) "
143157write_line " - Hyperfine version: $( hyperfine --version) "
158+ write_blank_line
159+ write_line " </details>"
144160
145161# Benchmark in the main repo
162+ write_section " CLI Commands" " Benchmarking basic commands in the main repo:"
163+
146164CMDS=(
147165 " --version"
148166 " list"
@@ -157,9 +175,9 @@ for cmd in "${CMDS[@]}"; do
157175 fi
158176
159177 if [[ " $cmd " == " --version" ]] || [[ " $cmd " == " list" ]]; then
160- benchmark " prek $cmd " " $cmd " 5 100
178+ benchmark " $cmd " 5 100
161179 else
162- benchmark " prek $cmd " " $cmd " 3 50
180+ benchmark " $cmd " 3 50
163181 fi
164182 check_variance " $cmd "
165183done
@@ -169,12 +187,12 @@ cd "$TARGET_WORKSPACE"
169187
170188# Cold vs warm benchmarks before polluting cache
171189write_section " Cold vs Warm Runs" " Comparing first run (cold) vs subsequent runs (warm cache):"
172- benchmark " prek run --all-files (cold - no cache) " " run --all-files " 0 10 " rm -rf ~/.cache/prek" " git checkout -- ."
173- benchmark " prek run --all-files (warm - with cache) " " run --all-files " 3 20 " " " git checkout -- ."
190+ benchmark " run --all-files" 0 10 " rm -rf ~/.cache/prek" " git checkout -- ." false " (cold - no cache) "
191+ benchmark " run --all-files" 3 20 " " " git checkout -- ." false " (warm - with cache) "
174192
175193# Full benchmark suite with cache warmed up
176194write_section " Full Hook Suite" " Running the builtin hook suite on the benchmark workspace:"
177- benchmark " prek run --all-files (full builtin hook suite) " " run --all-files " 3 50 " " " git checkout -- ." true
195+ benchmark " run --all-files" 3 50 " " " git checkout -- ." true " (full builtin hook suite) "
178196
179197# Individual hook performance
180198write_section " Individual Hook Performance" " Benchmarking each hook individually on the test repo:"
@@ -189,24 +207,24 @@ INDIVIDUAL_HOOKS=(
189207)
190208
191209for hook in " ${INDIVIDUAL_HOOKS[@]} " ; do
192- benchmark " prek run $hook --all-files " " run $hook --all-files" 3 30 " " " git checkout -- ."
210+ benchmark " run $hook --all-files" 3 30 " " " git checkout -- ."
193211done
194212
195213# Installation performance
196214write_section " Installation Performance" " Benchmarking hook installation (fast path hooks skip Python setup):"
197- benchmark " prek install-hooks (cold - no cache) " " install-hooks " 1 5 " rm -rf ~/.cache/prek/hooks ~/.cache/prek/repos"
198- benchmark " prek install-hooks (warm - with cache)" " install-hooks " 1 5
215+ benchmark " install-hooks" 1 5 " rm -rf ~/.cache/prek/hooks ~/.cache/prek/repos" " " false " (cold - no cache) "
216+ benchmark " install-hooks" 1 5 " " " " false " (warm - with cache)"
199217
200218# File filtering/scoping performance
201219write_section " File Filtering/Scoping Performance" " Testing different file selection modes:"
202220
203221git add -A
204- benchmark " prek run (staged files only) " " run " 3 20 " " " sh -c 'git checkout -- . && git add -A'"
205- benchmark " prek run --files '*.json' (specific file type) " " run --files '*.json' " 3 20
222+ benchmark " run" 3 20 " " " sh -c 'git checkout -- . && git add -A'" false " (staged files only) "
223+ benchmark " run --files '*.json'" 3 20 " " " " false " (specific file type) "
206224
207225# Workspace discovery & initialization
208226write_section " Workspace Discovery & Initialization" " Benchmarking hook discovery and initialization overhead:"
209- benchmark " prek run --dry-run --all-files (measures init overhead) " " run --dry-run --all-files " 3 20
227+ benchmark " run --dry-run --all-files" 3 20 " " " " false " (measures init overhead) "
210228
211229# Meta hooks performance
212230write_section " Meta Hooks Performance" " Benchmarking meta hooks separately:"
@@ -219,9 +237,11 @@ META_HOOKS=(
219237)
220238
221239for hook in " ${META_HOOKS[@]} " ; do
222- benchmark " prek run $hook --all-files " " run $hook --all-files" 3 15 " " " git checkout -- ."
240+ benchmark " run $hook --all-files" 3 15 " " " git checkout -- ."
223241done
224242
243+ close_section
244+
225245if [ " $failed " = true ]; then
226246 exit 1
227247fi
0 commit comments