-
-
Notifications
You must be signed in to change notification settings - Fork 0
258 lines (220 loc) · 9.87 KB
/
benchmark.yml
File metadata and controls
258 lines (220 loc) · 9.87 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
name: Benchmark
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
permissions:
contents: write
deployments: write
pull-requests: write
jobs:
benchmark:
name: Run Performance Benchmarks
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build project
run: npm run build
- name: Install benchmark dependencies
run: cd benchmarks && npm ci
- name: Build benchmarks
run: cd benchmarks && npm run build
- name: Run class-transformer comparison benchmark
run: |
npm run bench:compat > benchmark-compat.txt 2>&1 || echo "Comparison benchmark failed" > benchmark-compat.txt
cat benchmark-compat.txt
- name: Run class-validator comparison benchmark
run: |
npm run bench:validation > benchmark-validation.txt 2>&1 || echo "Validation benchmark failed" > benchmark-validation.txt
cat benchmark-validation.txt
- name: Run simple benchmark
continue-on-error: true
run: |
if [ -f "benchmarks/build/benchmarks/simple/Mapper.performance-benchmark.js" ]; then
cd benchmarks && node build/benchmarks/simple/Mapper.performance-benchmark.js > ../benchmark-simple.txt 2>&1
else
echo "Simple benchmark not available (file not found)" > benchmark-simple.txt
fi
- name: Run complex benchmark
continue-on-error: true
run: |
if [ -f "benchmarks/build/benchmarks/complex/Mapper.performance-benchmark.complex.js" ]; then
cd benchmarks && node build/benchmarks/complex/Mapper.performance-benchmark.complex.js > ../benchmark-complex.txt 2>&1
else
echo "Complex benchmark not available (file not found)" > benchmark-complex.txt
fi
- name: Build validation benchmarks
run: npm run bench:validation:build
- name: Generate JSON validation benchmark results for tracking
run: |
node benchmarks/suites/compat/validation-benchmark-action.js > bench-results.json 2>&1 || echo "[]" > bench-results.json
echo "Validation benchmark results for tracking:"
cat bench-results.json
- name: Save benchmark JSON files before cleanup
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
mkdir -p /tmp/benchmark-data
cp bench-results.json /tmp/benchmark-data/ || echo "[]" > /tmp/benchmark-data/bench-results.json
- name: Clean up benchmark text files before switching branches
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
git clean -fd
git reset --hard HEAD
- name: Restore benchmark JSON files after cleanup
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
cp /tmp/benchmark-data/bench-results.json .
- name: Store benchmark result (main branch only)
uses: benchmark-action/github-action-benchmark@v1
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
with:
name: om-data-mapper Performance
tool: 'customBiggerIsBetter'
output-file-path: bench-results.json
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: true
alert-threshold: '150%'
comment-on-alert: true
fail-on-alert: false
alert-comment-cc-users: '@Isqanderm'
summary-always: true
gh-pages-branch: gh-pages
benchmark-data-dir-path: dev/bench
- name: Upload benchmark results
uses: actions/upload-artifact@v4
with:
name: benchmark-results
path: |
bench-results.json
benchmark-simple.txt
benchmark-complex.txt
benchmark-compat.txt
benchmark-validation.txt
retention-days: 30
- name: Comment PR with comparison results
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
// Read all benchmark results
let compatResults = '';
let validationResults = '';
let simpleResults = '';
let complexResults = '';
try {
compatResults = fs.readFileSync('benchmark-compat.txt', 'utf8');
} catch (e) {
compatResults = 'Comparison benchmark not available';
}
try {
validationResults = fs.readFileSync('benchmark-validation.txt', 'utf8');
} catch (e) {
validationResults = 'Validation benchmark not available';
}
try {
simpleResults = fs.readFileSync('benchmark-simple.txt', 'utf8');
} catch (e) {
simpleResults = 'Simple benchmark not available';
}
try {
complexResults = fs.readFileSync('benchmark-complex.txt', 'utf8');
} catch (e) {
complexResults = 'Complex benchmark not available';
}
// Extract summary table and detailed results
const summaryMatch = compatResults.match(/📈 Summary[\s\S]*$/);
const summary = summaryMatch ? summaryMatch[0] : '';
// Extract individual scenario results for better formatting
const scenarios = [];
const scenarioRegex = /📊 Scenario \d+: (.+?)\n\s+class-transformer x ([\d,]+) ops\/sec[^\n]+\n\s+om-data-mapper x ([\d,]+) ops\/sec[^\n]+\n\s+✓ Fastest: (.+?)\n\s+⚡ Performance gain: ([\d.]+)% faster/g;
let match;
while ((match = scenarioRegex.exec(compatResults)) !== null) {
scenarios.push({
name: match[1],
ctOps: match[2],
omOps: match[3],
winner: match[4],
improvement: match[5]
});
}
// Build improved summary with visual indicators
let improvedSummary = '### 📊 Performance Comparison Summary\n\n';
if (scenarios.length > 0) {
improvedSummary += '| Scenario | class-transformer | om-data-mapper | Improvement |\n';
improvedSummary += '|----------|-------------------|----------------|-------------|\n';
scenarios.forEach(s => {
const improvement = parseFloat(s.improvement);
let badge = '';
if (improvement > 2000) badge = '🔥🔥🔥';
else if (improvement > 1000) badge = '🔥🔥';
else if (improvement > 500) badge = '🔥';
else badge = '⚡';
improvedSummary += '| ' + s.name + ' | ' + s.ctOps + ' ops/sec | ' +
s.omOps + ' ops/sec | **+' + s.improvement + '%** ' + badge + ' |\n';
});
// Calculate average
const avgImprovement = scenarios.reduce((sum, s) => sum + parseFloat(s.improvement), 0) / scenarios.length;
improvedSummary += '\n**Average Performance Gain: +' + avgImprovement.toFixed(2) + '%** 🚀\n\n';
improvedSummary += '> 🏆 **om-data-mapper won ' + scenarios.length + '/' + scenarios.length + ' scenarios**\n\n';
} else {
improvedSummary += '```\n' + summary + '\n```\n\n';
}
const body = '## 🚀 Performance Benchmark Results\n\n' +
'### 📦 class-transformer Compatibility\n\n' +
improvedSummary +
'<details>\n<summary>📋 Full class-transformer Benchmark Output</summary>\n\n' +
'```\n' + compatResults + '\n```\n\n</details>\n\n' +
'### ✅ class-validator Compatibility\n\n' +
'<details>\n<summary>📋 Full class-validator Benchmark Output</summary>\n\n' +
'```\n' + validationResults + '\n```\n\n</details>\n\n' +
'### 🎯 Core Performance\n\n' +
'<details>\n<summary>⚡ Simple Mapping Benchmark</summary>\n\n' +
'```\n' + simpleResults + '\n```\n\n</details>\n\n' +
'<details>\n<summary>🔧 Complex Transformations Benchmark</summary>\n\n' +
'```\n' + complexResults + '\n```\n\n</details>\n\n' +
'---\n' +
'💡 **Note:** These are absolute performance numbers from this PR.\n' +
'Historical performance trends will be available after merging to `main`.\n\n' +
'*Benchmarked with Benchmark.js on Node.js 20 • [View History](https://isqanderm.github.io/data-mapper/dev/bench/)*';
// Find existing benchmark comment
const { data: comments } = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('Performance Benchmark Results')
);
if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
comment_id: botComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});
} else {
// Create new comment
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});
}