drizzle 0.1.15

A type-safe SQL query builder for Rust
Documentation
name: Benchmarks

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
  workflow_dispatch:

env:
  CARGO_TERM_COLOR: always

jobs:
  benchmark-sqlite:
    name: Benchmark SQLite (${{ matrix.platform }})
    strategy:
      matrix:
        include:
          - os: ubuntu-latest
            platform: linux
            sqlite_features: "rusqlite,turso,uuid,query"
          - os: windows-latest
            platform: windows
            sqlite_features: "rusqlite,uuid,query"
          - os: macos-latest
            platform: macos
            sqlite_features: "rusqlite,turso,uuid,query"
    runs-on: ${{ matrix.os }}

    steps:
      - uses: actions/checkout@v6

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Cache Rust dependencies
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: bench-sqlite-${{ matrix.platform }}
          save-if: ${{ github.ref == 'refs/heads/main' }}

      - name: Restore Criterion baseline
        if: github.ref != 'refs/heads/main'
        uses: actions/cache/restore@v5
        with:
          path: target/criterion
          key: criterion-sqlite-${{ matrix.platform }}-main-
          restore-keys: |
            criterion-sqlite-${{ matrix.platform }}-main-

      - name: Run SQLite benchmarks (save baseline on main)
        if: github.ref == 'refs/heads/main'
        shell: bash
        run: |
          cargo bench --bench sqlite --features "${{ matrix.sqlite_features }}" -- \
            --save-baseline main \
            --output-format bencher \
            --color never | tee bench_output.txt

      - name: Run SQLite benchmarks (compare on PR or release branch)
        if: github.ref != 'refs/heads/main'
        shell: bash
        run: |
          cargo bench --bench sqlite --features "${{ matrix.sqlite_features }}" -- \
            --baseline-lenient main \
            --output-format bencher \
            --color never | tee bench_output.txt

      - name: Create report
        shell: bash
        run: |
          {
            echo "# SQLite Benchmarks"
            echo ""
            echo "**Date:** $(date -u '+%Y-%m-%d %H:%M:%S UTC')"
            echo "**Commit:** ${{ github.sha }}"
            echo "**Platform:** ${{ runner.os }} (${{ runner.arch }})"
            echo "**Features:** ${{ matrix.sqlite_features }}"
            echo "**Mode:** ${{ github.ref != 'refs/heads/main' && 'baseline compare' || 'baseline save' }}"
            echo ""
            echo '```'
            cat bench_output.txt
            echo '```'
          } > sqlite-${{ matrix.platform }}.md

      - name: Upload text report
        uses: actions/upload-artifact@v7
        with:
          name: benchmark-sqlite-${{ matrix.platform }}
          path: sqlite-${{ matrix.platform }}.md
          retention-days: 30

      - name: Upload Criterion reports
        uses: actions/upload-artifact@v7
        with:
          name: criterion-sqlite-${{ matrix.platform }}
          path: target/criterion
          retention-days: 14

      - name: Save Criterion baseline
        if: github.ref == 'refs/heads/main'
        uses: actions/cache/save@v5
        with:
          path: target/criterion
          key: criterion-sqlite-${{ matrix.platform }}-main-${{ github.sha }}

  benchmark-postgres:
    name: Benchmark PostgreSQL (linux)
    runs-on: ubuntu-latest

    services:
      postgres:
        image: postgres:18-alpine
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
          POSTGRES_DB: drizzle_test
        ports:
          - 5432:5432
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

    steps:
      - uses: actions/checkout@v6

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Cache Rust dependencies
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: bench-postgres
          save-if: ${{ github.ref == 'refs/heads/main' }}

      - name: Restore Criterion baseline
        if: github.ref != 'refs/heads/main'
        uses: actions/cache/restore@v5
        with:
          path: target/criterion
          key: criterion-postgres-main-
          restore-keys: |
            criterion-postgres-main-

      - name: Run PostgreSQL sync benchmarks (save baseline on main)
        if: github.ref == 'refs/heads/main'
        env:
          DATABASE_URL: "host=localhost user=postgres password=postgres dbname=drizzle_test"
        shell: bash
        run: |
          cargo bench --bench postgres --features "postgres-sync,uuid,query" -- \
            --save-baseline sync-main \
            --output-format bencher \
            --color never | tee sync_output.txt

      - name: Run PostgreSQL tokio benchmarks (save baseline on main)
        if: github.ref == 'refs/heads/main'
        env:
          DATABASE_URL: "host=localhost user=postgres password=postgres dbname=drizzle_test"
        shell: bash
        run: |
          cargo bench --bench postgres --features "tokio-postgres,uuid,query" -- \
            --save-baseline tokio-main \
            --output-format bencher \
            --color never | tee tokio_output.txt

      - name: Run PostgreSQL sync benchmarks (compare on PR or release branch)
        if: github.ref != 'refs/heads/main'
        env:
          DATABASE_URL: "host=localhost user=postgres password=postgres dbname=drizzle_test"
        shell: bash
        run: |
          cargo bench --bench postgres --features "postgres-sync,uuid,query" -- \
            --baseline-lenient sync-main \
            --output-format bencher \
            --color never | tee sync_output.txt

      - name: Run PostgreSQL tokio benchmarks (compare on PR or release branch)
        if: github.ref != 'refs/heads/main'
        env:
          DATABASE_URL: "host=localhost user=postgres password=postgres dbname=drizzle_test"
        shell: bash
        run: |
          cargo bench --bench postgres --features "tokio-postgres,uuid,query" -- \
            --baseline-lenient tokio-main \
            --output-format bencher \
            --color never | tee tokio_output.txt

      - name: Create report
        shell: bash
        run: |
          {
            echo "# PostgreSQL Benchmarks"
            echo ""
            echo "**Date:** $(date -u '+%Y-%m-%d %H:%M:%S UTC')"
            echo "**Commit:** ${{ github.sha }}"
            echo "**Platform:** ${{ runner.os }} (${{ runner.arch }})"
            echo "**Mode:** ${{ github.ref != 'refs/heads/main' && 'baseline compare' || 'baseline save' }}"
            echo ""
            echo "## sync"
            echo ""
            echo '```'
            cat sync_output.txt
            echo '```'
            echo ""
            echo "## tokio"
            echo ""
            echo '```'
            cat tokio_output.txt
            echo '```'
          } > postgres-linux.md

      - name: Upload text report
        uses: actions/upload-artifact@v7
        with:
          name: benchmark-postgres-linux
          path: postgres-linux.md
          retention-days: 30

      - name: Upload Criterion reports
        uses: actions/upload-artifact@v7
        with:
          name: criterion-postgres-linux
          path: target/criterion
          retention-days: 14

      - name: Save Criterion baseline
        if: github.ref == 'refs/heads/main'
        uses: actions/cache/save@v5
        with:
          path: target/criterion
          key: criterion-postgres-main-${{ github.sha }}