diff --git a/.github/workflows/master_benchmarks.yml b/.github/workflows/benchmarks.yml similarity index 54% rename from .github/workflows/master_benchmarks.yml rename to .github/workflows/benchmarks.yml index ad164c9b7..1d5d0a766 100644 --- a/.github/workflows/master_benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -1,8 +1,9 @@ -name: Master Benchmarks +name: Benchmarks on: push: branches: master + pull_request: workflow_dispatch: concurrency: @@ -14,9 +15,12 @@ env: php_version: "8.4" jobs: - run_benchmarks: - name: Run Master Benchmarks + benchmarks: + name: Run Benchmarks runs-on: ubuntu-latest + permissions: + contents: read + id-token: write steps: - uses: actions/checkout@v7 - name: Setup PHP @@ -31,6 +35,10 @@ jobs: toolchain: stable - name: Cache cargo dependencies uses: Swatinem/rust-cache@v2 + with: + workspaces: | + benches + benches/ext - name: Cache LLVM and Clang id: cache-llvm uses: actions/cache@v6 @@ -46,29 +54,18 @@ jobs: - name: Configure Clang run: | echo "LIBCLANG_PATH=${{ runner.temp }}/llvm-${{ env.clang }}/lib" >> $GITHUB_ENV - - name: Install Valgrind - run: sudo apt-get update && sudo apt-get install -y valgrind - uses: taiki-e/install-action@cargo-binstall - - name: Install gungraun-runner + - name: Install cargo-codspeed + run: cargo binstall --no-confirm cargo-codspeed + - name: Build extension and benchmarks + working-directory: benches run: | - version=$(cargo metadata --manifest-path ./benches/Cargo.toml --format-version=1 |\ - jq '.packages[] | select(.name == "gungraun").version' |\ - tr -d '"' - ) - cargo binstall --no-confirm --force gungraun-runner --version $version - echo "GUNGRAUN_RUNNER=$(which gungraun-runner)" >> $GITHUB_ENV + cargo build --manifest-path ext/Cargo.toml --release + cargo codspeed build - name: Run Benchmarks - run: cargo bench --manifest-path ./benches/Cargo.toml > benchmark_results.txt - env: - NO_COLOR: "1" - - uses: bencherdev/bencher@main - - name: Track Benchmarks with Bencher - run: | - bencher run \ - --project ext-php-rs \ - --token '${{ secrets.BENCHER_API_TOKEN }}' \ - --branch master \ - --testbed "$(php --version | head -n 1)" \ - --err \ - --adapter rust_gungraun \ - --file "./benchmark_results.txt" + uses: CodSpeedHQ/action@v5 + with: + mode: simulation + simulation-track-subprocess: true + working-directory: benches + run: cargo codspeed run diff --git a/.github/workflows/pr_benchmarks_archive.yml b/.github/workflows/pr_benchmarks_archive.yml deleted file mode 100644 index a9fb8ac05..000000000 --- a/.github/workflows/pr_benchmarks_archive.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Archive PR Benchmark Branch - -on: - pull_request_target: - types: [closed] - -jobs: - archive_fork_pr_branch: - name: Archive closed PR branch with Bencher - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v7 - - uses: bencherdev/bencher@main - - name: Archive closed fork PR branch with Bencher - run: | - bencher archive \ - --project ext-php-rs \ - --token '${{ secrets.BENCHER_API_TOKEN }}' \ - --branch "$GITHUB_HEAD_REF" diff --git a/.github/workflows/pr_benchmarks_run.yml b/.github/workflows/pr_benchmarks_run.yml deleted file mode 100644 index fca2b3d35..000000000 --- a/.github/workflows/pr_benchmarks_run.yml +++ /dev/null @@ -1,85 +0,0 @@ -name: Run Benchmarks - -on: - pull_request: - types: [opened, reopened, synchronize] - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -env: - clang: "17" - php_version: "8.4" - -jobs: - run_benchmarks: - name: Run PR Benchmarks - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v7 - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ env.php_version }} - env: - debug: true - - name: Setup Rust - uses: dtolnay/rust-toolchain@master - with: - toolchain: stable - - name: Cache cargo dependencies - uses: Swatinem/rust-cache@v2 - - name: Cache LLVM and Clang - id: cache-llvm - uses: actions/cache@v6 - with: - path: ${{ runner.temp }}/llvm-${{ env.clang }} - key: ubuntu-latest-llvm-${{ env.clang }} - - name: Setup LLVM & Clang - uses: KyleMayes/install-llvm-action@v2 - with: - version: ${{ env.clang }} - directory: ${{ runner.temp }}/llvm-${{ env.clang }} - cached: ${{ steps.cache-llvm.outputs.cache-hit }} - - name: Configure Clang - run: | - echo "LIBCLANG_PATH=${{ runner.temp }}/llvm-${{ env.clang }}/lib" >> $GITHUB_ENV - - name: Install Valgrind - run: sudo apt-get update && sudo apt-get install -y valgrind - - uses: taiki-e/install-action@cargo-binstall - - name: Install gungraun-runner - run: | - version=$(cargo metadata --manifest-path ./benches/Cargo.toml --format-version=1 |\ - jq '.packages[] | select(.name == "gungraun").version' |\ - tr -d '"' - ) - cargo binstall --no-confirm --force gungraun-runner --version $version - echo "GUNGRAUN_RUNNER=$(which gungraun-runner)" >> $GITHUB_ENV - - name: Run Benchmarks - run: cargo bench --manifest-path ./benches/Cargo.toml > benchmark_results.txt - env: - NO_COLOR: "1" - - name: Benchmark Summary - run: | - echo '## Benchmark Results' >> $GITHUB_STEP_SUMMARY - echo '```' >> $GITHUB_STEP_SUMMARY - sed 's/\x1b\[[0-9;]*m//g' benchmark_results.txt >> $GITHUB_STEP_SUMMARY - echo '```' >> $GITHUB_STEP_SUMMARY - - name: Upload Benchmark Results - uses: actions/upload-artifact@v7 - with: - name: benchmark_results.txt - path: ./benchmark_results.txt - - name: Save testbed name - run: php --version | head -n 1 > testbed.txt - - name: Upload Testbed - uses: actions/upload-artifact@v7 - with: - name: testbed.txt - path: ./testbed.txt - - name: Upload Pull Request Event - uses: actions/upload-artifact@v7 - with: - name: event.json - path: ${{ github.event_path }} diff --git a/.github/workflows/pr_benchmarks_upload.yml b/.github/workflows/pr_benchmarks_upload.yml deleted file mode 100644 index 5510841b6..000000000 --- a/.github/workflows/pr_benchmarks_upload.yml +++ /dev/null @@ -1,63 +0,0 @@ -name: Upload PR Benchmark Results - -on: - workflow_run: - workflows: [Run Benchmarks] - types: [completed] - -jobs: - upload_benchmarks: - if: github.event.workflow_run.conclusion == 'success' - permissions: - pull-requests: write - runs-on: ubuntu-latest - env: - BENCHMARK_RESULTS: benchmark_results.txt - PR_EVENT: event.json - steps: - - name: Download Benchmark Results - uses: dawidd6/action-download-artifact@v21 - with: - name: ${{ env.BENCHMARK_RESULTS }} - run_id: ${{ github.event.workflow_run.id }} - - name: Download PR Event - uses: dawidd6/action-download-artifact@v21 - with: - name: ${{ env.PR_EVENT }} - run_id: ${{ github.event.workflow_run.id }} - - name: Download Testbed - uses: dawidd6/action-download-artifact@v21 - with: - name: testbed.txt - run_id: ${{ github.event.workflow_run.id }} - - name: Export PR Event Data - uses: actions/github-script@v9 - with: - script: | - let fs = require('fs'); - let prEvent = JSON.parse(fs.readFileSync(process.env.PR_EVENT, {encoding: 'utf8'})); - core.exportVariable("PR_HEAD", prEvent.pull_request.head.ref); - core.exportVariable("PR_HEAD_SHA", prEvent.pull_request.head.sha); - core.exportVariable("PR_BASE", prEvent.pull_request.base.ref); - core.exportVariable("PR_BASE_SHA", prEvent.pull_request.base.sha); - core.exportVariable("PR_NUMBER", prEvent.number); - let testbed = fs.readFileSync('testbed.txt', {encoding: 'utf8'}).trim(); - core.exportVariable("TESTBED", testbed); - - uses: bencherdev/bencher@main - - name: Track Benchmarks with Bencher - run: | - bencher run \ - --project ext-php-rs \ - --token '${{ secrets.BENCHER_API_TOKEN }}' \ - --branch "$PR_HEAD" \ - --hash "$PR_HEAD_SHA" \ - --start-point "$PR_BASE" \ - --start-point-hash "$PR_BASE_SHA" \ - --start-point-clone-thresholds \ - --start-point-reset \ - --testbed "$TESTBED" \ - --err \ - --adapter rust_gungraun \ - --github-actions '${{ secrets.GITHUB_TOKEN }}' \ - --ci-number "$PR_NUMBER" \ - --file "$BENCHMARK_RESULTS" diff --git a/README.md b/README.md index 3544f4558..670722fc7 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ [![docs.rs](https://img.shields.io/docsrs/ext-php-rs/latest)](https://docs.rs/ext-php-rs) [![Guide Workflow Status](https://img.shields.io/github/actions/workflow/status/extphprs/ext-php-rs/docs.yml?branch=master&label=guide)](https://ext-php.rs) ![CI Workflow Status](https://img.shields.io/github/actions/workflow/status/extphprs/ext-php-rs/master.yml?branch=master) +[![CodSpeed Badge](https://img.shields.io/endpoint?url=https://app.codspeed.io//badge.json)](https://app.codspeed.io//extphprs/ext-php-rs?utm_source=badge) [![Coverage Status](https://coveralls.io/repos/github/extphprs/ext-php-rs/badge.svg?branch=master)](https://coveralls.io/github/extphprs/ext-php-rs?branch=master) [![Discord](https://img.shields.io/discord/115233111977099271)](https://discord.gg/dphp) Bindings and abstractions for the Zend API to build PHP extensions natively in diff --git a/benches/.gitignore b/benches/.gitignore index 0a833b78a..868471cca 100644 --- a/benches/.gitignore +++ b/benches/.gitignore @@ -1,3 +1,2 @@ /target /ext/target -callgrind.out.* diff --git a/benches/Cargo.toml b/benches/Cargo.toml index ddb9c0a6b..809b887ed 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -5,7 +5,7 @@ edition = "2024" publish = false [dependencies] -gungraun = "0.17.2" +divan = { package = "codspeed-divan-compat", version = "5.0.1" } [features] default = ["enum", "runtime", "closure"] diff --git a/benches/README.md b/benches/README.md new file mode 100644 index 000000000..aede34f47 --- /dev/null +++ b/benches/README.md @@ -0,0 +1,30 @@ +# Benchmarks + +Benchmarks spawn `php -dextension=ext/target/release/libbenches.so