-
Couldn't load subscription status.
- Fork 15
feat: PHPBench benchmarking #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8112e3d
feat: Add PHPBench benchmarking workflow and tests for ArrayDiffMulti…
rogervila 339064a
fix: Correct environment variable usage for branch checkouts in bench…
rogervila 751c4e6
fix: Update PHP setup action and specify benchmark test path in workflow
rogervila 805f607
fix: Remove redundant output option from benchmark run command
rogervila dc7bb85
fix: Ensure benchmark comparison directory is created before running …
rogervila File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| name: benchmark | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: | ||
| - master | ||
| types: [opened, synchronize, reopened] | ||
|
|
||
| jobs: | ||
| benchmark: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| # Step 1: Checkout the PR branch | ||
| - name: Checkout PR branch | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 # Fetch all history for comparison | ||
|
|
||
| # Step 2: Setup PHP | ||
| - name: Setup PHP | ||
| uses: shivammathur/setup-php@v2 | ||
| with: | ||
| php-version: '8.4' | ||
| extensions: zip, curl, mbstring, xml | ||
| coverage: none | ||
|
|
||
| # Step 3: Install dependencies for PR branch | ||
| - name: Install Composer dependencies | ||
| run: | | ||
| composer install --prefer-dist --no-progress --no-suggest | ||
| composer require --dev phpbench/phpbench | ||
|
|
||
| # Step 4: Run benchmarks on PR branch | ||
| - name: Run benchmarks on PR branch | ||
| run: | | ||
| ./vendor/bin/phpbench run \ | ||
| --report=default \ | ||
| --tag=pr \ | ||
| --retry-threshold=5 \ | ||
| --iterations=10 \ | ||
| --output=json > pr-results.json | ||
|
|
||
| # Step 5: Checkout base branch | ||
| - name: Checkout base branch | ||
| run: | | ||
| git fetch origin ${{ github.base_ref }} | ||
| git checkout origin/${{ github.base_ref }} | ||
|
|
||
| # Step 6: Install dependencies for base branch | ||
| - name: Install Composer dependencies (base) | ||
| run: | | ||
| composer install --prefer-dist --no-progress --no-suggest | ||
| composer require --dev phpbench/phpbench | ||
|
|
||
| # Step 7: Run benchmarks on base branch | ||
| - name: Run benchmarks on base branch | ||
| run: | | ||
| ./vendor/bin/phpbench run \ | ||
| --report=default \ | ||
| --tag=base \ | ||
| --retry-threshold=5 \ | ||
| --iterations=10 | ||
|
|
||
| # Step 8: Checkout PR branch again | ||
| - name: Checkout PR branch again | ||
| run: git checkout ${{ github.head_ref }} | ||
|
|
||
| # Step 9: Compare benchmarks | ||
| - name: Compare benchmarks with baseline | ||
| id: compare | ||
| run: | | ||
| ./vendor/bin/phpbench run \ | ||
| --report=aggregate \ | ||
| --ref=base \ | ||
| --retry-threshold=5 \ | ||
| --iterations=10 \ | ||
| --tag=pr \ | ||
| --assert="mode(variant.time.avg) <= mode(baseline.time.avg) +/- 10%" \ | ||
| | tee benchmark-comparison.txt | ||
| continue-on-error: true | ||
|
|
||
| # Step 10: Post results as PR comment | ||
| - name: Comment PR with benchmark results | ||
| uses: actions/github-script@v6 | ||
| with: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| script: | | ||
| const fs = require('fs'); | ||
| const results = fs.readFileSync('benchmark-comparison.txt', 'utf8'); | ||
|
|
||
| const body = `## 📊 Benchmark Results\n\n\`\`\`\n${results}\n\`\`\`\n\n**Note:** Benchmarks compare PR against \`${{ github.base_ref }}\` branch.\nPerformance regression threshold: ±10%`; | ||
|
|
||
| github.rest.issues.createComment({ | ||
| issue_number: context.issue.number, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| body: body | ||
| }); | ||
|
|
||
| # Step 11: Fail if performance degrades | ||
| - name: Check benchmark assertions | ||
| if: steps.compare.outcome == 'failure' | ||
| run: | | ||
| echo "::error::Performance regression detected! Benchmarks exceeded acceptable threshold." | ||
| exit 1 | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "$schema": "./vendor/phpbench/phpbench/phpbench.schema.json", | ||
| "runner.bootstrap": "vendor/autoload.php" | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.