-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (129 loc) · 5.27 KB
/
Copy pathperformance.yml
File metadata and controls
151 lines (129 loc) · 5.27 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
name: Performance Benchmarks
on:
push:
branches: [main]
pull_request:
branches: [main]
permissions:
contents: write
pull-requests: write
jobs:
benchmark:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: pip install -r requirements.txt
- name: Download previous benchmark data (current branch)
uses: actions/cache/restore@v4
with:
path: .benchmarks/branch
key: benchmark-${{ runner.os }}-${{ github.head_ref || github.ref_name }}-
restore-keys: |
benchmark-${{ runner.os }}-${{ github.head_ref || github.ref_name }}-
- name: Download main branch baseline
if: github.event_name == 'pull_request'
uses: actions/cache/restore@v4
with:
path: .benchmarks/main
key: benchmark-${{ runner.os }}-main-
restore-keys: |
benchmark-${{ runner.os }}-main-
- name: Copy previous results for comparison
run: |
mkdir -p .benchmarks/previous
if [ -f ".benchmarks/branch/benchmark-results.json" ]; then
cp .benchmarks/branch/benchmark-results.json .benchmarks/previous/last-run.json
fi
if [ -f ".benchmarks/main/benchmark-results.json" ]; then
cp .benchmarks/main/benchmark-results.json .benchmarks/previous/main-baseline.json
fi
- name: Run benchmarks
run: |
pytest tests/performance/ \
--benchmark-only \
--benchmark-json=benchmark-results.json \
--benchmark-compare \
--benchmark-autosave \
--benchmark-compare-fail=mean:10% \
|| true
- name: Save benchmark results for future comparisons
run: |
mkdir -p .benchmarks/branch
cp benchmark-results.json .benchmarks/branch/benchmark-results.json
- name: Cache benchmark results
uses: actions/cache/save@v4
with:
path: .benchmarks/branch
key: benchmark-${{ runner.os }}-${{ github.head_ref || github.ref_name }}-${{ github.run_id }}
- name: Cache main branch results
if: github.ref == 'refs/heads/main'
uses: actions/cache/save@v4
with:
path: .benchmarks/branch
key: benchmark-${{ runner.os }}-main-${{ github.run_id }}
- name: Store benchmark result
uses: actions/upload-artifact@v4
with:
name: benchmark-results
path: benchmark-results.json
- name: Comment benchmark results on PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const results = JSON.parse(fs.readFileSync('benchmark-results.json', 'utf8'));
// Load comparison data if available
let lastRun = null;
let mainBaseline = null;
try {
if (fs.existsSync('.benchmarks/previous/last-run.json')) {
lastRun = JSON.parse(fs.readFileSync('.benchmarks/previous/last-run.json', 'utf8'));
}
} catch (e) { console.log('No previous run data'); }
try {
if (fs.existsSync('.benchmarks/previous/main-baseline.json')) {
mainBaseline = JSON.parse(fs.readFileSync('.benchmarks/previous/main-baseline.json', 'utf8'));
}
} catch (e) { console.log('No main baseline data'); }
// Build lookup maps for comparison
const lastRunMap = {};
const mainBaselineMap = {};
if (lastRun?.benchmarks) {
for (const b of lastRun.benchmarks) {
lastRunMap[b.name] = b.stats.mean;
}
}
if (mainBaseline?.benchmarks) {
for (const b of mainBaseline.benchmarks) {
mainBaselineMap[b.name] = b.stats.mean;
}
}
// Helper to calculate % change
const pctChange = (current, baseline) => {
if (!baseline) return 'N/A';
const change = ((current - baseline) / baseline) * 100;
const sign = change > 0 ? '+' : '';
return `${sign}${change.toFixed(1)}%`;
};
let comment = '## Performance Benchmark Results\n\n';
comment += '| Test | Mean | OPS | vs Last | vs Main |\n';
comment += '|------|------|-----|---------|----------|\n';
for (const bench of results.benchmarks) {
const mean = (bench.stats.mean * 1000).toFixed(2);
const ops = bench.stats.ops.toFixed(2);
const vsLast = pctChange(bench.stats.mean, lastRunMap[bench.name]);
const vsMain = pctChange(bench.stats.mean, mainBaselineMap[bench.name]);
comment += `| ${bench.name} | ${mean}ms | ${ops} | ${vsLast} | ${vsMain} |\n`;
}
comment += '\n*Positive % = slower, Negative % = faster*\n';
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});