name: Benchmark

on:
  workflow_dispatch:
  push:
    branches:
      - main
  pull_request:

defaults:
  run:
    shell: bash

jobs:
  bench:
    name: Bench library
    runs-on: ubuntu-latest
    steps:
      - name: Install stable toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: 1.71.1

      - name: Install dependencies
        run: |
          sudo apt-get -qq -y update
          cargo install --quiet critcmp

      - name: Checkout baseline
        uses: actions/checkout@v3
        with:
          ref: ${{ github.base_ref }}

      - name: Install cargo-make
        run: cargo install --debug cargo-make

      - name: Benchmark baseline
        run: cargo make bench-baseline

      - name: Checkout changes
        uses: actions/checkout@v3

      - name: Benchmark changes
        run: cargo make bench-changes

      - name: Benchmark results
        run: cargo make bench-compare

      - name: Save results as artifact
        uses: actions/upload-artifact@v1
        with:
          name: Benchmark Results
          path: benchmark_results