name: bench
on:
push:
branches:
- "main"
workflow_dispatch:
inputs:
filter:
description: 'Optional filter for cargo bench (e.g., a specific benchmark name)'
default: ''
required: false
ref:
description: 'Optional git ref to benchmark'
default: ''
required: false
jobs:
benchmarks:
timeout-minutes: 30
runs-on: "ubicloud-standard-4-ubuntu-2404"
env:
CRITERION_HOME: ${{ github.workspace }}/.criterion_data
steps:
- name: Check out repository
uses: actions/checkout@v5
with:
submodules: recursive
ref: ${{ github.event.inputs.ref }}
- uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9
with:
toolchain: stable
- run: cargo --version
- name: CPU information
id: cpu-info
run: |
lscpu
echo "cpu_model=$(lscpu | grep 'Model name' | sed 's/Model name: *//g' | tr -d ' ')" >> $GITHUB_OUTPUT
- name: Cache compilation
uses: ubicloud/rust-cache@65b3ff06b9bcc69d88c25e212f1ae3d14a0953c3
- name: Restore criterion cache
id: restore-cache
uses: actions/cache/restore@v4
with:
path: ${{ env.CRITERION_HOME }}
key: ${{ runner.os }}-${{ runner.arch }}-${{ steps.cpu-info.outputs.cpu_model }}-criterion-data-${{ github.sha }}
restore-keys: |
${{ runner.os }}-${{ runner.arch }}-${{ steps.cpu-info.outputs.cpu_model }}-criterion-data-
- name: Run benchmarks
run: |
cargo bench --features "__bench" -- "${{ github.event.inputs.filter }}"
- name: Save criterion cache
if: ${{ !github.event.inputs.ref }}
uses: actions/cache/save@v4
with:
path: ${{ env.CRITERION_HOME }}
key: ${{ steps.restore-cache.outputs.cache-primary-key }}
- name: Upload benchmark reports
uses: actions/upload-artifact@v5
with:
name: benchmark-reports
path: ${{ env.CRITERION_HOME }}
include-hidden-files: true