Benchmark #23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Benchmark | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: "0 0 1 * *" | |
| permissions: | |
| contents: write | |
| jobs: | |
| benchmark: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v6 | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build forked version | |
| run: npm run build | |
| - name: Download non-forked version and changes | |
| run: | | |
| curl -L https://raw.githubusercontent.com/Metro420yt/class-update/refs/heads/master/dist/index.js -o benchmark/index.js | |
| curl -L https://raw.githubusercontent.com/SyndiShanX/Update-Classes/main/Changes.txt -o benchmark/Changes.txt | |
| - name: Verify functional parity | |
| run: | | |
| mkdir -p benchmark/fork benchmark/orig | |
| cp benchmark/Materialistic.css benchmark/fork/theme.css | |
| cp benchmark/Materialistic.css benchmark/orig/theme.css | |
| INPUT_FOLDER=benchmark/fork INPUT_DIFF=benchmark/Changes.txt INPUT_EXT=css node dist/index.js | |
| INPUT_FOLDER=benchmark/orig INPUT_DIFF=benchmark/Changes.txt INPUT_EXT=css node benchmark/index.js | |
| echo "Functional Comparison" | |
| echo "=====================" | |
| if diff -q benchmark/fork/theme.css benchmark/orig/theme.css; then | |
| echo "Outputs are identical." | |
| else | |
| echo "Outputs differ. Differences:" | |
| diff -u benchmark/orig/theme.css benchmark/fork/theme.css | head -n 20 || true | |
| fi | |
| - name: Install Hyperfine | |
| run: sudo apt-get install -y hyperfine | |
| - name: Run benchmark | |
| run: | | |
| hyperfine --warmup 3 --export-json results.json \ | |
| "INPUT_FOLDER=benchmark INPUT_DIFF=benchmark/Changes.txt INPUT_EXT=css node dist/index.js" \ | |
| "INPUT_FOLDER=benchmark INPUT_DIFF=benchmark/Changes.txt INPUT_EXT=css node benchmark/index.js" | |
| - name: Update README | |
| run: | | |
| FAST_MEAN=$(node -p "(require('./results.json').results[0].mean * 1000).toFixed(1)") | |
| SLOW_MEAN=$(node -p "(require('./results.json').results[1].mean * 1000).toFixed(1)") | |
| SPEEDUP=$(node -p "Math.round(require('./results.json').results[1].mean / require('./results.json').results[0].mean)") | |
| sed -i '/## Performance/,$d' README.md | |
| { | |
| echo "## Performance" | |
| echo "" | |
| echo "Benchmark conducted against \`Materialistic.css\` using the official \`Changes.txt\` dataset." | |
| echo "" | |
| echo "| Version | Execution Time |" | |
| echo "| :--- | :--- |" | |
| echo "| Fork | ${FAST_MEAN} ms |" | |
| echo "| Non-forked | ${SLOW_MEAN} ms |" | |
| echo "" | |
| echo "This version processed the theme in **${FAST_MEAN}ms** compared to **${SLOW_MEAN}ms** for the original, making it approximately **${SPEEDUP}x faster**." | |
| echo "" | |
| echo "## Migrating" | |
| echo "" | |
| echo "Change the step to:" | |
| echo "" | |
| echo "\`\`\`yml" | |
| echo "- uses: flowerey/class-update@main" | |
| echo "\`\`\`" | |
| } >> README.md | |
| - name: Commit and push changes | |
| run: | | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add README.md | |
| git commit -m "docs: update benchmark results" || echo "No changes to commit" | |
| git push |