|
| 1 | +# Performance Testing Workflow |
| 2 | +# |
| 3 | +# This workflow runs performance benchmarks to ensure the library remains fast and efficient. |
| 4 | +# It runs on every push/PR to main/master and can be triggered manually. |
| 5 | +# |
| 6 | +# What it measures: |
| 7 | +# 1. wcwidth function performance - how fast single character width calculation is |
| 8 | +# 2. wcswidth function performance - how fast string width calculation is |
| 9 | +# 3. Memory usage under load - ensures no memory leaks |
| 10 | +# 4. Bundle size - tracks if the package is getting larger |
| 11 | +# 5. Performance regression detection - compares against baselines |
| 12 | +# |
| 13 | +# This helps catch performance issues early and ensures the library stays performant. |
| 14 | + |
| 15 | +name: Performance Testing |
| 16 | + |
| 17 | +on: |
| 18 | + push: |
| 19 | + branches: [main, master] |
| 20 | + pull_request: |
| 21 | + branches: [main, master] |
| 22 | + workflow_dispatch: # Allow manual trigger |
| 23 | + |
| 24 | +jobs: |
| 25 | + benchmark: |
| 26 | + runs-on: ubuntu-latest |
| 27 | + |
| 28 | + steps: |
| 29 | + - name: Checkout |
| 30 | + uses: actions/checkout@v4 |
| 31 | + |
| 32 | + - name: Setup Node.js |
| 33 | + uses: actions/setup-node@v4 |
| 34 | + with: |
| 35 | + node-version: '20' |
| 36 | + cache: 'yarn' |
| 37 | + |
| 38 | + - name: Install dependencies |
| 39 | + run: yarn install --frozen-lockfile |
| 40 | + |
| 41 | + - name: Build project |
| 42 | + run: yarn build |
| 43 | + |
| 44 | + - name: Run performance benchmarks |
| 45 | + run: | |
| 46 | + echo "Running wcwidth performance tests..." |
| 47 | + node -e " |
| 48 | + const { wcwidth } = require('./dist/index.js'); |
| 49 | + const iterations = 1000000; |
| 50 | + const start = performance.now(); |
| 51 | + |
| 52 | + for (let i = 0; i < iterations; i++) { |
| 53 | + wcwidth(65); // 'A' |
| 54 | + wcwidth(0x4E00); // '一' |
| 55 | + wcwidth(0); // null |
| 56 | + } |
| 57 | + |
| 58 | + const end = performance.now(); |
| 59 | + const avgTime = (end - start) / iterations; |
| 60 | + console.log(\`wcwidth: \${avgTime.toFixed(6)}ms per call\`); |
| 61 | + console.log(\`Total time: \${(end - start).toFixed(2)}ms for \${iterations} calls\`); |
| 62 | + " |
| 63 | +
|
| 64 | + - name: Run wcswidth performance tests |
| 65 | + run: | |
| 66 | + echo "Running wcswidth performance tests..." |
| 67 | + node -e " |
| 68 | + const { wcswidth } = require('./dist/index.js'); |
| 69 | + const testStrings = [ |
| 70 | + 'Hello World', |
| 71 | + 'Hello 世界', |
| 72 | + 'A'.repeat(1000), |
| 73 | + '一'.repeat(100), |
| 74 | + 'Hello\u0000World' |
| 75 | + ]; |
| 76 | + |
| 77 | + const iterations = 10000; |
| 78 | + const start = performance.now(); |
| 79 | + |
| 80 | + for (let i = 0; i < iterations; i++) { |
| 81 | + testStrings.forEach(str => wcswidth(str)); |
| 82 | + } |
| 83 | + |
| 84 | + const end = performance.now(); |
| 85 | + const avgTime = (end - start) / (iterations * testStrings.length); |
| 86 | + console.log(\`wcswidth: \${avgTime.toFixed(6)}ms per call\`); |
| 87 | + console.log(\`Total time: \${(end - start).toFixed(2)}ms for \${iterations * testStrings.length} calls\`); |
| 88 | + " |
| 89 | +
|
| 90 | + - name: Memory usage test |
| 91 | + run: | |
| 92 | + echo "Testing memory usage..." |
| 93 | + node -e " |
| 94 | + const { wcswidth, wcwidth } = require('./dist/index.js'); |
| 95 | + |
| 96 | + const initialMemory = process.memoryUsage(); |
| 97 | + console.log('Initial memory:', initialMemory); |
| 98 | + |
| 99 | + // Perform intensive operations |
| 100 | + for (let i = 0; i < 100000; i++) { |
| 101 | + wcswidth('Hello World ' + i); |
| 102 | + wcwidth(i % 65536); |
| 103 | + } |
| 104 | + |
| 105 | + const finalMemory = process.memoryUsage(); |
| 106 | + console.log('Final memory:', finalMemory); |
| 107 | + |
| 108 | + const memoryIncrease = { |
| 109 | + heapUsed: finalMemory.heapUsed - initialMemory.heapUsed, |
| 110 | + heapTotal: finalMemory.heapTotal - initialMemory.heapTotal, |
| 111 | + external: finalMemory.external - initialMemory.external |
| 112 | + }; |
| 113 | + |
| 114 | + console.log('Memory increase:', memoryIncrease); |
| 115 | + " |
| 116 | +
|
| 117 | + - name: Bundle size check |
| 118 | + run: | |
| 119 | + echo "Checking bundle size..." |
| 120 | + du -h dist/index.js |
| 121 | + echo "Number of lines in dist:" |
| 122 | + find dist -name "*.js" -exec wc -l {} \; |
| 123 | +
|
| 124 | + - name: Performance regression check |
| 125 | + run: | |
| 126 | + echo "Checking for performance regressions..." |
| 127 | + # This would typically compare against baseline metrics |
| 128 | + # For now, we'll just log the current performance |
| 129 | + echo "Performance metrics logged above" |
| 130 | + echo "Consider setting up performance monitoring with tools like:" |
| 131 | + echo "- GitHub Actions performance tracking" |
| 132 | + echo "- Bundle size monitoring" |
| 133 | + echo "- Runtime performance baselines" |
0 commit comments