|
1 | 1 | const fs = require('fs'); |
2 | 2 | const path = require('path'); |
3 | | -const { execSync, spawnSync } = require('child_process'); |
| 3 | +const { spawnSync } = require('child_process'); |
4 | 4 |
|
5 | 5 | const COLD_RUNS = 5; |
6 | 6 | const WARM_RUNS = 5; |
7 | 7 | const STENCIL_BIN = path.join(__dirname, '..', '..', 'bin', 'stencil'); |
8 | 8 | const CACHE_DIR = path.join(__dirname, '.stencil'); |
9 | 9 | const RESULTS_FILE = path.join(__dirname, 'benchmark-results.json'); |
| 10 | +const SUMMARY_FILE = path.join(__dirname, 'benchmark-results.md'); |
10 | 11 |
|
11 | 12 | function clearCache() { |
12 | 13 | if (fs.existsSync(CACHE_DIR)) { |
@@ -64,6 +65,57 @@ function printStats(label, stats) { |
64 | 65 | console.log(` StdDev: ${formatMs(stats.stddev)}`); |
65 | 66 | } |
66 | 67 |
|
| 68 | +function generateMarkdown(results, history) { |
| 69 | + const { cold, warm } = results; |
| 70 | + |
| 71 | + const fmtValue = (ms) => formatMs(ms).padStart(8); |
| 72 | + |
| 73 | + let md = `# Stencil Compile Time Benchmark |
| 74 | +
|
| 75 | +**Last Run:** ${results.timestamp} |
| 76 | +**Node:** ${results.nodeVersion} | **Platform:** ${results.platform} (${results.arch}) |
| 77 | +
|
| 78 | +## Latest Results |
| 79 | +
|
| 80 | +### Cold Builds (no cache) |
| 81 | +
|
| 82 | +| Metric | Value | |
| 83 | +|----------|----------| |
| 84 | +| Min | ${fmtValue(cold.min)} | |
| 85 | +| Max | ${fmtValue(cold.max)} | |
| 86 | +| **Avg** | **${formatMs(cold.avg)}** | |
| 87 | +| Median | ${fmtValue(cold.median)} | |
| 88 | +| StdDev | ${fmtValue(cold.stddev)} | |
| 89 | +
|
| 90 | +### Warm Builds (with cache) |
| 91 | +
|
| 92 | +| Metric | Value | |
| 93 | +|----------|----------| |
| 94 | +| Min | ${fmtValue(warm.min)} | |
| 95 | +| Max | ${fmtValue(warm.max)} | |
| 96 | +| **Avg** | **${formatMs(warm.avg)}** | |
| 97 | +| Median | ${fmtValue(warm.median)} | |
| 98 | +| StdDev | ${fmtValue(warm.stddev)} | |
| 99 | +
|
| 100 | +## History |
| 101 | +
|
| 102 | +| Date | Cold Avg | Warm Avg | Node | |
| 103 | +|------------|----------|----------|----------| |
| 104 | +`; |
| 105 | + |
| 106 | + // Add history rows (most recent first, limit to 10) |
| 107 | + const recentHistory = [...history].reverse().slice(0, 10); |
| 108 | + for (const entry of recentHistory) { |
| 109 | + const date = new Date(entry.timestamp).toLocaleDateString().padEnd(10); |
| 110 | + const coldAvg = formatMs(entry.cold.avg).padStart(8); |
| 111 | + const warmAvg = formatMs(entry.warm.avg).padStart(8); |
| 112 | + const node = entry.nodeVersion.padEnd(8); |
| 113 | + md += `| ${date} | ${coldAvg} | ${warmAvg} | ${node} |\n`; |
| 114 | + } |
| 115 | + |
| 116 | + return md; |
| 117 | +} |
| 118 | + |
67 | 119 | async function main() { |
68 | 120 | console.log('Stencil Compilation Time Benchmark'); |
69 | 121 | console.log('==================================='); |
@@ -127,9 +179,15 @@ async function main() { |
127 | 179 |
|
128 | 180 | history.push(results); |
129 | 181 |
|
| 182 | + // Save JSON |
130 | 183 | fs.writeFileSync(RESULTS_FILE, JSON.stringify({ latest: results, history }, null, 2)); |
131 | 184 |
|
132 | | - console.log(`\nResults saved to ${RESULTS_FILE}`); |
| 185 | + // Save Markdown summary |
| 186 | + fs.writeFileSync(SUMMARY_FILE, generateMarkdown(results, history)); |
| 187 | + |
| 188 | + console.log(`\nResults saved to:`); |
| 189 | + console.log(` ${RESULTS_FILE}`); |
| 190 | + console.log(` ${SUMMARY_FILE}`); |
133 | 191 | } |
134 | 192 |
|
135 | 193 | main().catch((err) => { |
|
0 commit comments