1- import { existsSync , readFileSync , writeFileSync } from 'fs' ;
1+ import { existsSync , readFileSync , writeFileSync } from 'node: fs' ;
22
3- const current = JSON . parse ( readFileSync ( 'benchmark-result.json' , 'utf-8' ) ) ;
4- const baseline = existsSync ( 'benchmark-baseline.json' ) ? JSON . parse ( readFileSync ( 'benchmark-baseline.json' , 'utf-8' ) ) : [ ] ;
3+ const loadJson = ( path ) => {
4+ return existsSync ( path ) ? JSON . parse ( readFileSync ( path , 'utf-8' ) ) : [ ] ;
5+ } ;
56
6- let hasRegression = false ;
7+ const current = loadJson ( 'benchmark-result.json' ) ;
8+ const baseline = loadJson ( 'benchmark-baseline.json' ) ;
79
8- let markdown = `## Hydration Benchmark Report (vs Baseline)\n\n` ;
9- markdown += `| Component | Current | Baseline | Δ% | Result |\n` ;
10- markdown += `|-----------|---------|----------|-----|--------|\n` ;
10+ const rows = [ ] ;
11+ let hasRegression = false ;
1112
1213for ( const entry of current ) {
1314 const prev = baseline . find ( ( b ) => b . name === entry . name ) ;
1415 const now = entry . value ;
1516
1617 if ( ! prev ) {
17- markdown += `| \`${ entry . name } \` | ${ now } ms | – | – | 🆕 |\n` ;
18+ rows . push ( {
19+ name : entry . name ,
20+ current : now ,
21+ baseline : null ,
22+ percent : null ,
23+ markdown : `| \`${ entry . name } \` | ${ now } ms | – | – | 🆕 |` ,
24+ } ) ;
1825 continue ;
1926 }
2027
@@ -25,9 +32,35 @@ for (const entry of current) {
2532
2633 if ( percent > 5 ) hasRegression = true ;
2734
28- markdown += `| \`${ entry . name } \` | ${ now } ms | ${ old } ms | ${ diffStr } | ${ emoji } |\n` ;
35+ rows . push ( {
36+ name : entry . name ,
37+ current : now ,
38+ baseline : old ,
39+ percent,
40+ markdown : `| \`${ entry . name } \` | ${ now } ms | ${ old } ms | ${ diffStr } | ${ emoji } |` ,
41+ } ) ;
2942}
3043
44+ const top5 = rows
45+ . filter ( ( r ) => r . percent !== null )
46+ . sort ( ( a , b ) => Math . abs ( b . percent ) - Math . abs ( a . percent ) )
47+ . slice ( 0 , 5 ) ;
48+
49+ const rest = rows . filter ( ( r ) => ! top5 . includes ( r ) ) . sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) ;
50+
51+ let markdown = `## Hydration Benchmark Report (vs Baseline)\n\n` ;
52+
53+ markdown += `### 📊 Top 5 Änderungen\n\n` ;
54+ markdown += `| Component | Current | Baseline | Δ% | Result |\n` ;
55+ markdown += `|-----------|---------|----------|-----|--------|\n` ;
56+ markdown += top5 . map ( ( r ) => r . markdown ) . join ( '\n' ) + '\n\n' ;
57+
58+ markdown += `<details>\n<summary>📋 Alle Ergebnisse anzeigen</summary>\n\n` ;
59+ markdown += `| Component | Current | Baseline | Δ% | Result |\n` ;
60+ markdown += `|-----------|---------|----------|-----|--------|\n` ;
61+ markdown += rest . map ( ( r ) => r . markdown ) . join ( '\n' ) + '\n' ;
62+ markdown += `</details>\n` ;
63+
3164writeFileSync ( 'benchmark-report.md' , markdown ) ;
3265
3366if ( hasRegression ) {
0 commit comments