Skip to content

Commit

Permalink
CI : Added the benchmark workflow in CI (#385)
Browse files Browse the repository at this point in the history
It is adding the benchmark workflow to CI. It is resolving the issue #266
  • Loading branch information
ItshMoh authored Mar 3, 2025
1 parent 0c15d67 commit d0e0708
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Benchmarks

on:
pull_request:
branches: ["master"]

env:
CARGO_TERM_COLOR: always

jobs:
benchmark:
name: Run Benchmarks
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: dtolnay/[email protected]
with:
components: rustfmt, clippy

# Bi-weekly numbers to refresh caches every two weeks, ensuring recent project changes are cached
- name: Set bi-weekly cache key
# Use '10#' to always treat week number as base-10 (avoids octal when number has a leading zero)
run: |
YEAR=$(date +%Y)
WEEK=$(date +%U)
BIWEEK=$(( (10#$WEEK + 1) / 2 ))
echo "CACHE_VERSION=${YEAR}(${BIWEEK})" >> $GITHUB_ENV
# Hash of all files that could affect the build
echo "BUILD_HASH=${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }}" >> $GITHUB_ENV
shell: bash

# Restore Rust build cache and artifacts
- name: Restore Rust cache
id: cache
uses: actions/cache/restore@v4
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/release/
# Cache key depends on the bi-week we are on (cache version)
key: ${{ runner.os }}-cargo-${{ env.CACHE_VERSION }}-${{ env.BUILD_HASH }}
restore-keys: |
${{ runner.os }}-cargo-${{ env.CACHE_VERSION }}-
${{ runner.os }}-cargo-
# Run benchmarks
- name: Run cargo bench
run: cargo bench

# Save cache only if the previous steps succeeded and there was not an exact cache key match
# This happens everytime we modify any `cargo.lock` or `cargo.toml`, or each two weeks (caching recent changes)
- name: Save Rust cache
if: success() && steps.cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/release/
key: ${{ steps.cache.outputs.cache-primary-key }}

# Store benchmark results
- name: Store benchmark results
uses: actions/upload-artifact@v4
with:
name: benchmark-results
path: target/criterion

0 comments on commit d0e0708

Please sign in to comment.