-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
192 lines (184 loc) · 8.22 KB
/
Copy pathhyperfine.yml
File metadata and controls
192 lines (184 loc) · 8.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
name: hyperfine
on:
pull_request:
branches: ["main"]
# paths:
# - ".github/workflows/hyperfine.yml"
# - "Cargo.toml"
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
GITHUB_TOKEN: ${{ secrets.MISE_GH_TOKEN || secrets.GITHUB_TOKEN }}
MISE_EXPERIMENTAL: 1
permissions:
issues: write
pull-requests: write
jobs:
benchmark:
runs-on: namespace-profile-endev-linux-amd64-large;overrides.cache-tag=mise-pr-rust-linux
timeout-minutes: 30
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
with:
fetch-depth: 0
- uses: namespacelabs/nscloud-cache-action@58bf6e08898e88803c098e2b522668541cd3b2e3 # v1
with:
path: |
~/.cargo/registry
~/.cargo/git
~/.cargo/.global-cache
~/.cache/sccache
- uses: taiki-e/install-action@51cd0b8c0499559d9a4d75c0f5c67bec3a894ec8 # v2
with: { tool: sccache }
- name: Configure sccache
run: |
export RUSTC_WRAPPER=sccache
export SCCACHE_DIR="$HOME/.cache/sccache"
export SCCACHE_CACHE_SIZE=20G
{
echo "RUSTC_WRAPPER=$RUSTC_WRAPPER"
echo "SCCACHE_DIR=$SCCACHE_DIR"
echo "SCCACHE_CACHE_SIZE=$SCCACHE_CACHE_SIZE"
} >> "$GITHUB_ENV"
sccache --zero-stats
- run: curl https://mise.run | MISE_INSTALL_PATH="$HOME/bin/mise-release" sh
- run: echo "$HOME/bin" >> "$GITHUB_PATH"
- id: versions
run: |
#echo "main=$(git rev-parse --short origin/main)" >> "$GITHUB_OUTPUT"
echo "release=$(mise-release v | awk '{print $1}')" >> "$GITHUB_OUTPUT"
#- uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4
# with:
# path: ~/bin/mise-${{ steps.versions.outputs.main }}
# key: mise-hyperfine-main-${{ steps.versions.outputs.main }}-${{ runner.os }}-${{ runner.arch }}
#- name: build main
# run: |
# if [ ! -f "$HOME/bin/mise-${{ steps.versions.outputs.main }}" ]; then
# git checkout main
# cargo build --profile serious && mv target/serious/mise "$HOME/bin/mise-${{ steps.versions.outputs.main }}"
# git checkout -
# fi
- run: mv "$HOME/bin/mise-release" "$HOME/bin/mise-${{ steps.versions.outputs.release }}"
#- run: cp "$HOME/bin/mise-${{ steps.versions.outputs.main }}" "$HOME/bin/mise-main"
- run: cargo build --profile serious && mv target/serious/mise "$HOME/bin"
- uses: ./.github/actions/mise-tools
- run: |
set -exo pipefail
failed=false
outlier_warning="Statistical outliers were detected"
threshold_scaled=1100
scale_decimal() {
local number="$1"
local whole fraction
whole=${number%%.*}
fraction=${number#*.}
if [ "$fraction" = "$number" ]; then
fraction=0
fi
fraction="${fraction}000"
echo $((10#$whole * 1000 + 10#${fraction:0:3}))
}
CMDS=(
"x -- echo"
"env"
"hook-env"
"ls"
)
echo "## Hyperfine Performance" >> comment.md
for cmd in "${CMDS[@]}"; do
hyperfine_log="$(mktemp)"
reference_cmd="${MISE_ALT:-mise-${{ steps.versions.outputs.release }}} $cmd"
current_cmd="mise $cmd"
mise x hyperfine -- hyperfine -N -w 10 -r 500 --export-markdown out.md --reference "$reference_cmd" "$current_cmd" 2>&1 | tee "$hyperfine_log"
echo "### \`mise $cmd\`" >> comment.md
cat out.md >> comment.md
cat out.md
noisy=false
if grep -q "$outlier_warning" "$hyperfine_log"; then
noisy=true
fi
# Extract relative performance from hyperfine output
relative_row="$(grep "±.*±" out.md || true)"
if [ -z "$relative_row" ]; then
echo "::warning title=Missing hyperfine relative result::Could not find a relative result for mise $cmd."
echo "⚠️ Inconclusive: could not find a relative result for \`$cmd\`." >> comment.md
rm -f "$hyperfine_log"
continue
fi
variance=$(printf '%s\n' "$relative_row" | awk '{print $(NF-3)}' | sed 's/%//')
uncertainty=$(printf '%s\n' "$relative_row" | awk '{print $(NF-1)}' | sed 's/%//')
if [ -z "$variance" ] || [ -z "$uncertainty" ]; then
echo "::warning title=Malformed hyperfine relative result::Could not parse the relative result for mise $cmd."
echo "⚠️ Inconclusive: could not parse the relative result for \`$cmd\`." >> comment.md
rm -f "$hyperfine_log"
continue
fi
variance_scaled=$(scale_decimal "$variance")
uncertainty_scaled=$(scale_decimal "$uncertainty")
variance=$(((variance_scaled - 1000) / 10))
# Add warning if variance exceeds 10%
if [ "$variance_scaled" -gt "$threshold_scaled" ]; then
if printf '%s\n' "$relative_row" | grep -Fq "| \`$reference_cmd\` |"; then
echo "✅ Performance improvement for \`$cmd\` is ${variance}%" >> comment.md
elif [ "$noisy" = true ]; then
echo "::warning title=Noisy hyperfine result::mise $cmd measured ${variance}% slower, but hyperfine reported statistical outliers. Treating this benchmark as inconclusive."
echo "⚠️ Inconclusive: \`$cmd\` measured ${variance}% slower, but hyperfine reported statistical outliers." >> comment.md
elif [ "$((variance_scaled - uncertainty_scaled))" -le "$threshold_scaled" ]; then
echo "::warning title=Inconclusive hyperfine result::mise $cmd measured ${variance}% slower, but the relative uncertainty overlaps the 10% threshold. Treating this benchmark as inconclusive."
echo "⚠️ Inconclusive: \`$cmd\` measured ${variance}% slower, but the relative uncertainty overlaps the 10% threshold." >> comment.md
else
echo "⚠️ Warning: Performance variance for \`$cmd\` is ${variance}%" >> comment.md
failed=true
fi
fi
rm -f "$hyperfine_log"
done
if [ "$failed" = true ]; then
exit 1
fi
env:
SHELL: zsh
- run: mise run test:perf
if: ${{ !cancelled() }}
env:
NUM_TOOLS: 200
NUM_TASKS: 2000
RUNS: 10
MISE_ALT: mise-${{ steps.versions.outputs.release }}
- if: ${{ !cancelled() }}
run: sccache --show-stats
- run: cat comment.md >> "$GITHUB_STEP_SUMMARY"
if: ${{ !cancelled() && github.event_name == 'pull_request' }}
- name: Comment on PR
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
if: ${{ !cancelled() && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository }}
continue-on-error: true
with:
script: |
const fs = require("fs");
const marker = "<!-- hyperfine -->";
const body = `${marker}\n${fs.readFileSync("comment.md", "utf8")}`;
const comments = await github.paginate(github.rest.issues.listComments, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const comment = comments.find((comment) => comment.body?.includes(marker));
if (comment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comment.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}